Commit 69759ade authored by Guillaume Seguin's avatar Guillaume Seguin

Mostly revert 099c68ef as we can do it in a cleaner way now

parent a511f209
......@@ -37,12 +37,6 @@ class PyLine(object):
def __getattr__(self, name):
return None
def setstring(self, name, value):
self.set(name, value)
def set(self, name, value):
setattr(self, name, value)
try:
import gcoder_line
LineBase = gcoder_line.GLine
......@@ -55,10 +49,10 @@ class Line(LineBase):
def __init__(self, l):
super(Line, self).__init__()
self.setstring("raw", l)
self.set("split_raw", gcode_exp.findall(self.raw.lower()))
self.setstring("command", self.split_raw[0].upper() if not self.split_raw[0].startswith("n") else self.split_raw[1].upper())
self.set("is_move", self.command in move_gcodes)
self.raw = l
self.split_raw = gcode_exp.findall(self.raw.lower())
self.command = self.split_raw[0].upper() if not self.split_raw[0].startswith("n") else self.split_raw[1].upper()
self.is_move = self.command in move_gcodes
def parse_coordinates(self, imperial = False, force = False):
# Not a G-line, we don't want to parse its arguments
......@@ -68,13 +62,13 @@ class Line(LineBase):
for bit in self.split_raw:
code = bit[0]
if code in gcode_parsed_args and len(bit) > 1:
self.set(code, 25.4*float(bit[1:]))
setattr(self, code, 25.4*float(bit[1:]))
else:
for bit in self.split_raw:
code = bit[0]
if code in gcode_parsed_args and len(bit) > 1:
self.set(code, float(bit[1:]))
self.set("split_raw", None)
setattr(self, code, float(bit[1:]))
del self.split_raw
def __repr__(self):
return self.raw
......@@ -130,9 +124,9 @@ class Layer(object):
current_y = line.y or current_y
current_z = line.z or current_z
line.set("current_x", current_x)
line.set("current_y", current_y)
line.set("current_z", current_z)
line.current_x = current_x
line.current_y = current_y
line.current_z = current_z
return (current_x, current_y, current_z), (xmin, xmax), (ymin, ymax), (zmin, zmax)
class GCode(object):
......@@ -199,9 +193,9 @@ class GCode(object):
current_tool = self.current_tool
for line in lines:
if line.is_move:
line.set("relative", relative)
line.set("relative_e", relative_e)
line.set("current_tool", current_tool)
line.relative = relative
line.relative_e = relative_e
line.current_tool = current_tool
elif line.command == "G20":
imperial = True
elif line.command == "G21":
......@@ -237,10 +231,10 @@ class GCode(object):
continue
if line.is_move:
if line.relative_e:
line.set("extruding", line.e != 0)
line.extruding = line.e != 0
total_e += line.e
else:
line.set("extruding", line.e != cur_e)
line.extruding = line.e != cur_e
total_e += line.e - cur_e
cur_e = line.e
max_e = max(max_e, total_e)
......
......@@ -21,6 +21,14 @@ cdef extern from "string.h":
char *strncpy(char *dest, char *src, size_t n)
size_t strlen(const char *s)
cdef char* copy_string(object value):
cdef char* orig = value
str_len = len(orig)
cdef char* array = <char *>malloc(str_len + 1)
strncpy(array, orig, str_len)
array[str_len] = 0;
return array
cdef class GLine(object):
cdef public float _x, _y, _z, _e, _f, _i, _j, _s, _p
......@@ -184,32 +192,20 @@ cdef class GLine(object):
def __set__(self, value):
self._split_raw = value
self.has_split_raw = True
def __del__(self):
del self._split_raw
self.has_split_raw = False
property raw:
def __get__(self):
if self.has_raw: return self._raw
else: return None
def __set__(self, value):
self._raw = value
self._raw = copy_string(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._command = copy_string(value)
self.has_command = True
def setstring(self, name, value):
cdef char* orig = value
str_len = len(orig)
cdef char* array = <char *>malloc(str_len + 1)
strncpy(array, orig, str_len);
array[str_len] = 0;
if name == "raw":
self._raw = array
elif name == "command":
self._command = array
setattr(self, "has_" + name, True)
def set(self, name, value):
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