printrun-src/printrun/gcoder_line.pyx

Fri, 24 Aug 2018 10:27:47 +0200

author
mdd
date
Fri, 24 Aug 2018 10:27:47 +0200
changeset 38
700241b53fe7
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

disabled power management, since it prevents also going monitor to sleep

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is copied from GCoder.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # GCoder is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # GCoder is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 from libc.stdlib cimport malloc, free
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 from libc.stdint cimport uint8_t, uint32_t
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 from libc.string cimport strlen, strncpy
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 cdef char* copy_string(object value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 cdef char* orig = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 str_len = len(orig)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 cdef char* array = <char *>malloc(str_len + 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 strncpy(array, orig, str_len)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 array[str_len] = 0;
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 return array
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 cdef enum BitPos:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 pos_raw = 1 << 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 pos_command = 1 << 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 pos_is_move = 1 << 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 pos_x = 1 << 3
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 pos_y = 1 << 4
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 pos_z = 1 << 5
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 pos_e = 1 << 6
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 pos_f = 1 << 7
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 pos_i = 1 << 8
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 pos_j = 1 << 9
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 pos_relative = 1 << 10
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 pos_relative_e = 1 << 11
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 pos_extruding = 1 << 12
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 pos_current_x = 1 << 13
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 pos_current_y = 1 << 14
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 pos_current_z = 1 << 15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 pos_current_tool = 1 << 16
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 pos_gcview_end_vertex = 1 << 17
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 # WARNING: don't use bits 24 to 31 as we store current_tool there
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 cdef inline uint32_t has_var(uint32_t status, uint32_t pos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 return status & pos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 cdef inline uint32_t set_has_var(uint32_t status, uint32_t pos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 return status | pos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 cdef inline uint32_t unset_has_var(uint32_t status, uint32_t pos):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 return status & ~pos
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 cdef class GLine:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 cdef char* _raw
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 cdef char* _command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 cdef float _x, _y, _z, _e, _f, _i, _j
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 cdef float _current_x, _current_y, _current_z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 cdef uint32_t _gcview_end_vertex
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 cdef uint32_t _status
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 __slots__ = ()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 def __cinit__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 self._status = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 self._raw = NULL
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 self._command = NULL
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 def __init__(self, line):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 self.raw = line
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 def __dealloc__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 if self._raw != NULL: free(self._raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 if self._command != NULL: free(self._command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 property x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 if has_var(self._status, pos_x): return self._x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 self._x = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 self._status = set_has_var(self._status, pos_x)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 property y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 if has_var(self._status, pos_y): return self._y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 self._y = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 self._status = set_has_var(self._status, pos_y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 property z:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 if has_var(self._status, pos_z): return self._z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 self._z = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 self._status = set_has_var(self._status, pos_z)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 property e:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 if has_var(self._status, pos_e): return self._e
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 self._e = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 self._status = set_has_var(self._status, pos_e)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 property f:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 if has_var(self._status, pos_f): return self._f
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 self._f = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 self._status = set_has_var(self._status, pos_f)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 property i:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 if has_var(self._status, pos_i): return self._i
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 self._i = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 self._status = set_has_var(self._status, pos_i)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 property j:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 if has_var(self._status, pos_j): return self._j
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 self._j = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 self._status = set_has_var(self._status, pos_j)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 property is_move:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132 if has_var(self._status, pos_is_move): return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 else: return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 if value: self._status = set_has_var(self._status, pos_is_move)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 else: self._status = unset_has_var(self._status, pos_is_move)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 property relative:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 if has_var(self._status, pos_relative): return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 else: return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 if value: self._status = set_has_var(self._status, pos_relative)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 else: self._status = unset_has_var(self._status, pos_relative)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 property relative_e:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 if has_var(self._status, pos_relative_e): return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 else: return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 if value: self._status = set_has_var(self._status, pos_relative_e)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 else: self._status = unset_has_var(self._status, pos_relative_e)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 property extruding:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 if has_var(self._status, pos_extruding): return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 else: return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 if value: self._status = set_has_var(self._status, pos_extruding)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 else: self._status = unset_has_var(self._status, pos_extruding)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 property current_x:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 if has_var(self._status, pos_current_x): return self._current_x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 self._current_x = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 self._status = set_has_var(self._status, pos_current_x)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 property current_y:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 if has_var(self._status, pos_current_y): return self._current_y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 self._current_y = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 self._status = set_has_var(self._status, pos_current_y)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 property current_z:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 if has_var(self._status, pos_current_z): return self._current_z
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 self._current_z = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178 self._status = set_has_var(self._status, pos_current_z)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 property current_tool:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 if has_var(self._status, pos_current_tool): return self._status >> 24
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 self._status = (self._status & ((1 << 24) - 1)) | (value << 24)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 self._status = set_has_var(self._status, pos_current_tool)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 property gcview_end_vertex:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 if has_var(self._status, pos_gcview_end_vertex): return self._gcview_end_vertex
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 self._gcview_end_vertex = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 self._status = set_has_var(self._status, pos_gcview_end_vertex)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 property raw:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 if has_var(self._status, pos_raw): return self._raw
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 # WARNING: memory leak could happen here, as we don't do the following :
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 # if self._raw != NULL: free(self._raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 self._raw = copy_string(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 self._status = set_has_var(self._status, pos_raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 property command:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 if has_var(self._status, pos_command): return self._command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 # WARNING: memory leak could happen here, as we don't do the following :
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 # if self._command != NULL: free(self._command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 self._command = copy_string(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 self._status = set_has_var(self._status, pos_command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 cdef class GLightLine:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 cdef char* _raw
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 cdef char* _command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216 cdef uint8_t _status
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 __slots__ = ()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 def __cinit__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 self._status = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 self._raw = NULL
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 self._command = NULL
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 def __init__(self, line):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 self.raw = line
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 def __dealloc__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 if self._raw != NULL: free(self._raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 if self._command != NULL: free(self._command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 property raw:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 if has_var(self._status, pos_raw): return self._raw
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 # WARNING: memory leak could happen here, as we don't do the following :
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 # if self._raw != NULL: free(self._raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 self._raw = copy_string(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 self._status = set_has_var(self._status, pos_raw)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 property command:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 if has_var(self._status, pos_command): return self._command
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 else: return None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 # WARNING: memory leak could happen here, as we don't do the following :
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 # if self._command != NULL: free(self._command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 self._command = copy_string(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 self._status = set_has_var(self._status, pos_command)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 property is_move:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251 def __get__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 if has_var(self._status, pos_is_move): return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 else: return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 def __set__(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 if value: self._status = set_has_var(self._status, pos_is_move)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 else: self._status = unset_has_var(self._status, pos_is_move)

mercurial