forked from spegelius/filaswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.py
105 lines (89 loc) · 2.64 KB
/
layer.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
from gcode import GCode
gcode = GCode()
class Layer:
def __init__(self, num, z, height):
self.num = num
self.z = z
self.lines = []
self.height = height
self.line_index = 0
def add_line(self, cmd, comment):
"""
Adds lines to line list
:param cmd: g-code command
:param comment: comment
:return:
"""
self.lines.append((cmd, comment))
def is_empty_layer(self):
"""
Check if layer is empty, i.e. no commands
:return: true or false
"""
for cmd, _ in self.lines:
if cmd:
return False
return True
def insert_line(self, index, cmd, comment):
"""
Insert line to given index position
:param index: index
:param cmd: g-code command
:param comment: g-code comment
:return: none
"""
self.lines.insert(index, (cmd, comment))
def replace_line(self, index, cmd, comment):
"""
Replace line in given index position
:param index: index
:param cmd: g-code command
:param comment: g-code comment
:return: none
"""
self.lines[index] = (cmd, comment)
def has_tool_changes(self):
"""
Check if layer has tool changes
:return: true or false
"""
for cmd, _ in self.lines:
if cmd and gcode.is_tool_change(cmd) is not None:
return True
return False
def delete_line(self, index=None):
"""
Deletes line from line list
:param index: index to delete
:return:
"""
if not index:
l_index = self.line_index
else:
l_index = index
self.lines.pop(l_index)
def remove_comments(self):
""" Removes comment lines """
self.line_index = 0
while True:
try:
if self.lines[self.line_index].startswith(b";"):
self.lines.pop(self.line_index)
continue
self.lines[self.line_index] = self.lines[self.line_index].split(b";")[0].strip()
self.line_index += 1
except IndexError:
return
def read_lines(self):
"""
Read lines, return also line index
:return: list of line values (cmd, comment and index)
"""
index = 0
for line in self.lines:
yield line[0], line[1], index
index += 1
class FirstLayer(Layer):
def __init__(self, num, z, height):
super().__init__(num, z, height)
self.start_gcode_end = 0