Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
a1a83be1
Commit
a1a83be1
authored
Mar 29, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework GCoder to factorize preprocessing in a single function #423
parent
b179b572
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
182 additions
and
197 deletions
+182
-197
gcoder.py
printrun/gcoder.py
+182
-197
No files found.
printrun/gcoder.py
View file @
a1a83be1
...
@@ -116,6 +116,8 @@ class GCode(object):
...
@@ -116,6 +116,8 @@ class GCode(object):
current_z
=
0
current_z
=
0
# For E this is the absolute position from machine start
# For E this is the absolute position from machine start
current_e
=
0
current_e
=
0
total_e
=
0
max_e
=
0
# Current feedrate
# Current feedrate
current_f
=
0
current_f
=
0
# Offset: current offset between the machine origin and the machine current
# Offset: current offset between the machine origin and the machine current
...
@@ -190,16 +192,16 @@ class GCode(object):
...
@@ -190,16 +192,16 @@ class GCode(object):
return
len
(
self
.
all_zs
)
return
len
(
self
.
all_zs
)
layers_count
=
property
(
_get_layers_count
)
layers_count
=
property
(
_get_layers_count
)
def
__init__
(
self
,
data
=
None
,
home_pos
=
None
):
def
__init__
(
self
,
data
=
None
,
home_pos
=
None
,
layer_callback
=
None
):
self
.
home_pos
=
home_pos
self
.
home_pos
=
home_pos
if
data
:
if
data
:
self
.
lines
=
[
Line
(
l2
)
for
l2
in
self
.
lines
=
[
Line
(
l2
)
for
l2
in
(
l
.
strip
()
for
l
in
data
)
(
l
.
strip
()
for
l
in
data
)
if
l2
]
if
l2
]
self
.
_preprocess
_lines
()
self
.
_preprocess
(
build_layers
=
True
,
self
.
filament_length
=
self
.
_preprocess_extrusion
(
)
layer_callback
=
layer_callback
)
self
.
_create_layers
()
self
.
filament_length
=
self
.
max_e
self
.
_
preprocess_layers
()
self
.
_
compute_bounding_box
()
else
:
else
:
self
.
lines
=
[]
self
.
lines
=
[]
self
.
append_layer_id
=
0
self
.
append_layer_id
=
0
...
@@ -220,8 +222,7 @@ class GCode(object):
...
@@ -220,8 +222,7 @@ class GCode(object):
if
not
command
:
if
not
command
:
return
return
gline
=
Line
(
command
)
gline
=
Line
(
command
)
self
.
_preprocess_lines
([
gline
])
self
.
_preprocess
([
gline
])
self
.
_preprocess_extrusion
([
gline
])
if
store
:
if
store
:
self
.
lines
.
append
(
gline
)
self
.
lines
.
append
(
gline
)
self
.
append_layer
.
append
(
gline
)
self
.
append_layer
.
append
(
gline
)
...
@@ -229,7 +230,8 @@ class GCode(object):
...
@@ -229,7 +230,8 @@ class GCode(object):
self
.
line_idxs
.
append
(
len
(
self
.
append_layer
))
self
.
line_idxs
.
append
(
len
(
self
.
append_layer
))
return
gline
return
gline
def
_preprocess_lines
(
self
,
lines
=
None
):
def
_preprocess
(
self
,
lines
=
None
,
build_layers
=
False
,
layer_callback
=
None
):
"""Checks for imperial/relativeness settings and tool changes"""
"""Checks for imperial/relativeness settings and tool changes"""
if
not
lines
:
if
not
lines
:
lines
=
self
.
lines
lines
=
self
.
lines
...
@@ -244,11 +246,30 @@ class GCode(object):
...
@@ -244,11 +246,30 @@ class GCode(object):
offset_y
=
self
.
offset_y
offset_y
=
self
.
offset_y
offset_z
=
self
.
offset_z
offset_z
=
self
.
offset_z
current_e
=
self
.
current_e
offset_e
=
self
.
offset_e
total_e
=
self
.
total_e
max_e
=
self
.
max_e
# Initialize layers
if
build_layers
:
all_layers
=
self
.
all_layers
=
[]
layer_idxs
=
self
.
layer_idxs
=
[]
line_idxs
=
self
.
line_idxs
=
[]
layer_id
=
0
layer_line
=
0
last_layer_z
=
None
prev_z
=
None
prev_base_z
=
(
None
,
None
)
cur_z
=
None
cur_lines
=
[]
for
line
in
lines
:
for
line
in
lines
:
## Parse line
split_raw
=
split
(
line
)
split_raw
=
split
(
line
)
if
not
line
.
command
:
if
line
.
command
:
continue
# Update properties
# Update properties
if
line
.
is_move
:
if
line
.
is_move
:
line
.
relative
=
relative
line
.
relative
=
relative
...
@@ -316,29 +337,9 @@ class GCode(object):
...
@@ -316,29 +337,9 @@ class GCode(object):
line
.
current_x
=
current_x
line
.
current_x
=
current_x
line
.
current_y
=
current_y
line
.
current_y
=
current_y
line
.
current_z
=
current_z
line
.
current_z
=
current_z
self
.
imperial
=
imperial
self
.
relative
=
relative
self
.
relative_e
=
relative_e
self
.
current_tool
=
current_tool
self
.
current_x
=
current_x
self
.
current_y
=
current_y
self
.
current_z
=
current_z
self
.
offset_x
=
offset_x
self
.
offset_y
=
offset_y
self
.
offset_z
=
offset_z
def
_preprocess_extrusion
(
self
,
lines
=
None
):
if
not
lines
:
lines
=
self
.
lines
current_e
=
self
.
current_e
## Process extrusion
offset_e
=
self
.
offset_e
if
line
.
e
is
not
None
:
total_e
=
0
max_e
=
0
for
line
in
lines
:
if
line
.
e
is
None
:
continue
if
line
.
is_move
:
if
line
.
is_move
:
if
line
.
relative_e
:
if
line
.
relative_e
:
line
.
extruding
=
line
.
e
>
0
line
.
extruding
=
line
.
e
>
0
...
@@ -353,26 +354,10 @@ class GCode(object):
...
@@ -353,26 +354,10 @@ class GCode(object):
elif
line
.
command
==
"G92"
:
elif
line
.
command
==
"G92"
:
offset_e
=
current_e
-
line
.
e
offset_e
=
current_e
-
line
.
e
self
.
current_e
=
current_e
## Create layers
self
.
offset_e
=
offset_e
if
not
build_layers
:
return
max_e
continue
# FIXME : looks like this needs to be tested with "lift Z on move"
# FIXME : looks like this needs to be tested with list Z on move
def
_create_layers
(
self
):
layers
=
{}
all_layers
=
[]
layer_idxs
=
[]
line_idxs
=
[]
layer_id
=
0
layer_line
=
0
last_layer_z
=
None
prev_z
=
None
prev_base_z
=
(
None
,
None
)
cur_z
=
None
cur_lines
=
[]
for
line
in
self
.
lines
:
if
line
.
command
==
"G92"
and
line
.
z
is
not
None
:
if
line
.
command
==
"G92"
and
line
.
z
is
not
None
:
cur_z
=
line
.
z
cur_z
=
line
.
z
elif
line
.
is_move
:
elif
line
.
is_move
:
...
@@ -403,55 +388,55 @@ class GCode(object):
...
@@ -403,55 +388,55 @@ class GCode(object):
if
base_z
!=
prev_base_z
:
if
base_z
!=
prev_base_z
:
all_layers
.
append
(
Layer
(
cur_lines
,
base_z
))
all_layers
.
append
(
Layer
(
cur_lines
,
base_z
))
old_lines
=
layers
.
get
(
base_z
,
[])
old_lines
+=
cur_lines
layers
[
base_z
]
=
old_lines
cur_lines
=
[]
cur_lines
=
[]
layer_id
+=
1
layer_id
+=
1
layer_line
=
0
layer_line
=
0
last_layer_z
=
base_z
last_layer_z
=
base_z
if
layer_callback
is
not
None
:
layer_callback
(
self
,
len
(
all_layers
)
-
1
)
prev_base_z
=
base_z
prev_base_z
=
base_z
if
build_layers
:
cur_lines
.
append
(
line
)
cur_lines
.
append
(
line
)
layer_idxs
.
append
(
layer_id
)
layer_idxs
.
append
(
layer_id
)
line_idxs
.
append
(
layer_line
)
line_idxs
.
append
(
layer_line
)
layer_line
+=
1
layer_line
+=
1
prev_z
=
cur_z
prev_z
=
cur_z
### Loop done
# Store current status
self
.
imperial
=
imperial
self
.
relative
=
relative
self
.
relative_e
=
relative_e
self
.
current_tool
=
current_tool
self
.
current_x
=
current_x
self
.
current_y
=
current_y
self
.
current_z
=
current_z
self
.
offset_x
=
offset_x
self
.
offset_y
=
offset_y
self
.
offset_z
=
offset_z
self
.
current_e
=
current_e
self
.
offset_e
=
offset_e
self
.
max_e
=
max_e
self
.
total_e
=
total_e
# Finalize layers
if
build_layers
:
if
cur_lines
:
if
cur_lines
:
all_layers
.
append
(
Layer
(
cur_lines
,
prev_z
))
all_layers
.
append
(
Layer
(
cur_lines
,
prev_z
))
old_lines
=
layers
.
get
(
prev_z
,
[])
old_lines
+=
cur_lines
layers
[
prev_z
]
=
old_lines
for
zindex
in
layers
.
keys
():
cur_lines
=
layers
[
zindex
]
has_movement
=
False
for
l
in
layers
[
zindex
]:
if
l
.
is_move
and
l
.
e
is
not
None
:
has_movement
=
True
break
if
has_movement
:
layers
[
zindex
]
=
Layer
(
cur_lines
,
zindex
)
else
:
del
layers
[
zindex
]
self
.
append_layer_id
=
len
(
all_layers
)
self
.
append_layer_id
=
len
(
all_layers
)
self
.
append_layer
=
Layer
([])
self
.
append_layer
=
Layer
([])
all_layers
.
append
(
self
.
append_layer
)
all_layers
.
append
(
self
.
append_layer
)
self
.
all_layers
=
all_layers
self
.
layers
=
layers
self
.
layer_idxs
=
array
(
'I'
,
layer_idxs
)
self
.
layer_idxs
=
array
(
'I'
,
layer_idxs
)
self
.
line_idxs
=
array
(
'I'
,
line_idxs
)
self
.
line_idxs
=
array
(
'I'
,
line_idxs
)
def
idxs
(
self
,
i
):
def
idxs
(
self
,
i
):
return
self
.
layer_idxs
[
i
],
self
.
line_idxs
[
i
]
return
self
.
layer_idxs
[
i
],
self
.
line_idxs
[
i
]
def
num_layers
(
self
):
def
_compute_bounding_box
(
self
):
return
len
(
self
.
layers
)
def
_preprocess_layers
(
self
):
xmin
=
float
(
"inf"
)
xmin
=
float
(
"inf"
)
ymin
=
float
(
"inf"
)
ymin
=
float
(
"inf"
)
zmin
=
0
zmin
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment