Commit a511f209 authored by Guillaume Seguin's avatar Guillaume Seguin

Rewrite gcoder_line to use properties instead of hacking setattr

parent a3b27af5
......@@ -26,7 +26,7 @@ cdef class GLine(object):
cdef public float _x, _y, _z, _e, _f, _i, _j, _s, _p
cdef public bool _is_move, _relative, _relative_e, _extruding
cdef public float _current_x, _current_y, _current_z
cdef public int _current_tool
cdef public char _current_tool
cdef public long _gcview_end_vertex
cdef char* _raw
cdef char* _command
......@@ -48,18 +48,156 @@ cdef class GLine(object):
self._command = NULL
def __dealloc__(self):
if self._raw: free(self._raw)
if self._command: free(self._command)
if self._raw != NULL: free(self._raw)
if self._command != NULL: free(self._command)
def __getattr__(self, name):
if getattr(self, "has_" + name):
if name == "raw":
return self._raw
elif name == "command":
return self._command
return getattr(self, "_" + name)
else:
return None
property x:
def __get__(self):
if self.has_x: return self._x
else: return None
def __set__(self, value):
self._x = value
self.has_x = True
property y:
def __get__(self):
if self.has_y: return self._y
else: return None
def __set__(self, value):
self._y = value
self.has_y = True
property z:
def __get__(self):
if self.has_z: return self._z
else: return None
def __set__(self, value):
self._z = value
self.has_z = True
property e:
def __get__(self):
if self.has_e: return self._e
else: return None
def __set__(self, value):
self._e = value
self.has_e = True
property f:
def __get__(self):
if self.has_f: return self._f
else: return None
def __set__(self, value):
self._f = value
self.has_f = True
property i:
def __get__(self):
if self.has_i: return self._i
else: return None
def __set__(self, value):
self._i = value
self.has_i = True
property j:
def __get__(self):
if self.has_j: return self._j
else: return None
def __set__(self, value):
self._j = value
self.has_j = True
property s:
def __get__(self):
if self.has_s: return self._s
else: return None
def __set__(self, value):
self._s = value
self.has_s = True
property p:
def __get__(self):
if self.has_p: return self._p
else: return None
def __set__(self, value):
self._p = value
self.has_p = True
property is_move:
def __get__(self):
if self.has_is_move: return self._is_move
else: return None
def __set__(self, value):
self._is_move = value
self.has_is_move = True
property relative:
def __get__(self):
if self.has_relative: return self._relative
else: return None
def __set__(self, value):
self._relative = value
self.has_relative = True
property relative_e:
def __get__(self):
if self.has_relative_e: return self._relative_e
else: return None
def __set__(self, value):
self._relative_e = value
self.has_relative_e = True
property extruding:
def __get__(self):
if self.has_extruding: return self._extruding
else: return None
def __set__(self, value):
self._extruding = value
self.has_extruding = True
property current_x:
def __get__(self):
if self.has_current_x: return self._current_x
else: return None
def __set__(self, value):
self._current_x = value
self.has_current_x = True
property current_y:
def __get__(self):
if self.has_current_y: return self._current_y
else: return None
def __set__(self, value):
self._current_y = value
self.has_current_y = True
property current_z:
def __get__(self):
if self.has_current_z: return self._current_z
else: return None
def __set__(self, value):
self._current_z = value
self.has_current_z = True
property current_tool:
def __get__(self):
if self.has_current_tool: return self._current_tool
else: return None
def __set__(self, value):
self._current_tool = value
self.has_current_tool = True
property gcview_end_vertex:
def __get__(self):
if self.has_gcview_end_vertex: return self._gcview_end_vertex
else: return None
def __set__(self, value):
self._gcview_end_vertex = value
self.has_gcview_end_vertex = True
property split_raw:
def __get__(self):
if self.has_split_raw: return self._split_raw
else: return None
def __set__(self, value):
self._split_raw = value
self.has_split_raw = True
property raw:
def __get__(self):
if self.has_raw: return self._raw
else: return None
def __set__(self, value):
self._raw = value
self.has_raw = True
property command:
def __get__(self):
if self.has_command: return self._command
else: return None
def __set__(self, value):
self._command = value
self.has_command = True
def setstring(self, name, value):
cdef char* orig = value
......@@ -74,5 +212,4 @@ cdef class GLine(object):
setattr(self, "has_" + name, True)
def set(self, name, value):
setattr(self, "_" + name, value)
setattr(self, "has_" + name, True)
setattr(self, name, value)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment