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
77888d9a
Commit
77888d9a
authored
Jun 14, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Heavily refactor gcoder to trim memory consumption again
parent
4de130a1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
49 deletions
+39
-49
GCodeAnalyzer.py
printrun/GCodeAnalyzer.py
+2
-1
gcoder.py
printrun/gcoder.py
+27
-31
gcoder_line.pyx
printrun/gcoder_line.pyx
+6
-14
pronterface.py
pronterface.py
+4
-3
No files found.
printrun/GCodeAnalyzer.py
View file @
77888d9a
...
@@ -69,8 +69,9 @@ class GCodeAnalyzer():
...
@@ -69,8 +69,9 @@ class GCodeAnalyzer():
def
Analyze
(
self
,
gcode
):
def
Analyze
(
self
,
gcode
):
gline
=
gcoder
.
Line
(
gcode
)
gline
=
gcoder
.
Line
(
gcode
)
split_raw
=
gcoder
.
split
(
gline
)
if
gline
.
command
.
startswith
(
";@"
):
return
# code is a host command
if
gline
.
command
.
startswith
(
";@"
):
return
# code is a host command
g
line
.
parse_coordinates
(
self
.
imperial
)
g
coder
.
parse_coordinates
(
gline
,
split_raw
,
self
.
imperial
)
code_g
=
int
(
gline
.
command
[
1
:])
if
gline
.
command
.
startswith
(
"G"
)
else
None
code_g
=
int
(
gline
.
command
[
1
:])
if
gline
.
command
.
startswith
(
"G"
)
else
None
code_m
=
int
(
gline
.
command
[
1
:])
if
gline
.
command
.
startswith
(
"M"
)
else
None
code_m
=
int
(
gline
.
command
[
1
:])
if
gline
.
command
.
startswith
(
"M"
)
else
None
...
...
printrun/gcoder.py
View file @
77888d9a
...
@@ -34,44 +34,38 @@ class PyLine(object):
...
@@ -34,44 +34,38 @@ class PyLine(object):
'current_x'
,
'current_y'
,
'current_z'
,
'extruding'
,
'current_tool'
,
'current_x'
,
'current_y'
,
'current_z'
,
'extruding'
,
'current_tool'
,
'gcview_end_vertex'
)
'gcview_end_vertex'
)
def
__init__
(
self
,
l
):
self
.
raw
=
l
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
return
None
return
None
try
:
try
:
import
gcoder_line
import
gcoder_line
Line
Base
=
gcoder_line
.
GLine
Line
=
gcoder_line
.
GLine
except
ImportError
:
except
ImportError
:
LineBase
=
PyLine
Line
=
PyLine
class
Line
(
LineBase
):
__slots__
=
()
def
split
(
line
):
split_raw
=
gcode_exp
.
findall
(
line
.
raw
.
lower
())
line
.
command
=
split_raw
[
0
]
.
upper
()
if
not
split_raw
[
0
]
.
startswith
(
"n"
)
else
split_raw
[
1
]
.
upper
()
line
.
is_move
=
line
.
command
in
move_gcodes
return
split_raw
def
__init__
(
self
,
l
):
def
parse_coordinates
(
line
,
split_raw
,
imperial
=
False
,
force
=
False
):
super
(
Line
,
self
)
.
__init__
()
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
# Not a G-line, we don't want to parse its arguments
if
not
force
and
not
self
.
command
[
0
]
=
=
"G"
:
if
not
force
and
line
.
command
[
0
]
!
=
"G"
:
return
return
if
imperial
:
if
imperial
:
for
bit
in
self
.
split_raw
:
for
bit
in
split_raw
:
code
=
bit
[
0
]
code
=
bit
[
0
]
if
code
in
gcode_parsed_args
and
len
(
bit
)
>
1
:
if
code
in
gcode_parsed_args
and
len
(
bit
)
>
1
:
setattr
(
self
,
code
,
25.4
*
float
(
bit
[
1
:]))
setattr
(
line
,
code
,
25.4
*
float
(
bit
[
1
:]))
else
:
else
:
for
bit
in
self
.
split_raw
:
for
bit
in
split_raw
:
code
=
bit
[
0
]
code
=
bit
[
0
]
if
code
in
gcode_parsed_args
and
len
(
bit
)
>
1
:
if
code
in
gcode_parsed_args
and
len
(
bit
)
>
1
:
setattr
(
self
,
code
,
float
(
bit
[
1
:]))
setattr
(
line
,
code
,
float
(
bit
[
1
:]))
del
self
.
split_raw
def
__repr__
(
self
):
return
self
.
raw
class
Layer
(
object
):
class
Layer
(
object
):
...
@@ -192,6 +186,7 @@ class GCode(object):
...
@@ -192,6 +186,7 @@ class GCode(object):
relative_e
=
self
.
relative_e
relative_e
=
self
.
relative_e
current_tool
=
self
.
current_tool
current_tool
=
self
.
current_tool
for
line
in
lines
:
for
line
in
lines
:
split_raw
=
split
(
line
)
if
line
.
is_move
:
if
line
.
is_move
:
line
.
relative
=
relative
line
.
relative
=
relative
line
.
relative_e
=
relative_e
line
.
relative_e
=
relative_e
...
@@ -213,7 +208,7 @@ class GCode(object):
...
@@ -213,7 +208,7 @@ class GCode(object):
elif
line
.
command
[
0
]
==
"T"
:
elif
line
.
command
[
0
]
==
"T"
:
current_tool
=
int
(
line
.
command
[
1
:])
current_tool
=
int
(
line
.
command
[
1
:])
if
line
.
command
[
0
]
==
"G"
:
if
line
.
command
[
0
]
==
"G"
:
line
.
parse_coordinates
(
imperial
)
parse_coordinates
(
line
,
split_raw
,
imperial
)
self
.
imperial
=
imperial
self
.
imperial
=
imperial
self
.
relative
=
relative
self
.
relative
=
relative
self
.
relative_e
=
relative_e
self
.
relative_e
=
relative_e
...
@@ -408,6 +403,7 @@ def main():
...
@@ -408,6 +403,7 @@ def main():
print
"usage:
%
s filename.gcode"
%
sys
.
argv
[
0
]
print
"usage:
%
s filename.gcode"
%
sys
.
argv
[
0
]
return
return
print
"Line object size:"
,
sys
.
getsizeof
(
Line
(
"G0 X0"
))
gcode
=
GCode
(
open
(
sys
.
argv
[
1
]))
gcode
=
GCode
(
open
(
sys
.
argv
[
1
]))
print
"Dimensions:"
print
"Dimensions:"
...
...
printrun/gcoder_line.pyx
View file @
77888d9a
...
@@ -47,9 +47,8 @@ cdef enum BitPos:
...
@@ -47,9 +47,8 @@ cdef enum BitPos:
pos_current_z = 1 << 15
pos_current_z = 1 << 15
pos_current_tool = 1 << 16
pos_current_tool = 1 << 16
pos_raw = 1 << 17
pos_raw = 1 << 17
pos_split_raw = 1 << 18
pos_command = 1 << 18
pos_command = 1 << 19
pos_gcview_end_vertex = 1 << 19
pos_gcview_end_vertex = 1 << 20
cdef inline uint32_t has_var(uint32_t status, uint32_t pos):
cdef inline uint32_t has_var(uint32_t status, uint32_t pos):
return status & pos
return status & pos
...
@@ -60,11 +59,10 @@ cdef inline uint32_t set_has_var(uint32_t status, uint32_t pos):
...
@@ -60,11 +59,10 @@ cdef inline uint32_t set_has_var(uint32_t status, uint32_t pos):
cdef inline uint32_t unset_has_var(uint32_t status, uint32_t pos):
cdef inline uint32_t unset_has_var(uint32_t status, uint32_t pos):
return status & ~pos
return status & ~pos
cdef class GLine
(object)
:
cdef class GLine:
cdef char* _raw
cdef char* _raw
cdef char* _command
cdef char* _command
cdef object _split_raw
cdef float _x, _y, _z, _e, _f, _i, _j, _s, _p
cdef float _x, _y, _z, _e, _f, _i, _j, _s, _p
cdef float _current_x, _current_y, _current_z
cdef float _current_x, _current_y, _current_z
cdef uint32_t _gcview_end_vertex
cdef uint32_t _gcview_end_vertex
...
@@ -78,6 +76,9 @@ cdef class GLine(object):
...
@@ -78,6 +76,9 @@ cdef class GLine(object):
self._raw = NULL
self._raw = NULL
self._command = NULL
self._command = NULL
def __init__(self, line):
self.raw = line
def __dealloc__(self):
def __dealloc__(self):
if self._raw != NULL: free(self._raw)
if self._raw != NULL: free(self._raw)
if self._command != NULL: free(self._command)
if self._command != NULL: free(self._command)
...
@@ -208,15 +209,6 @@ cdef class GLine(object):
...
@@ -208,15 +209,6 @@ cdef class GLine(object):
def __set__(self, value):
def __set__(self, value):
self._gcview_end_vertex = value
self._gcview_end_vertex = value
self._status = set_has_var(self._status, pos_gcview_end_vertex)
self._status = set_has_var(self._status, pos_gcview_end_vertex)
property split_raw:
def __get__(self):
if has_var(self._status, pos_split_raw): return self._split_raw
else: return None
def __set__(self, value):
self._split_raw = value
self._status = set_has_var(self._status, pos_split_raw)
def __del__(self):
self._split_raw = None
property raw:
property raw:
def __get__(self):
def __get__(self):
if has_var(self._status, pos_raw): return self._raw
if has_var(self._status, pos_raw): return self._raw
...
...
pronterface.py
View file @
77888d9a
...
@@ -367,7 +367,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
...
@@ -367,7 +367,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
def
sentcb
(
self
,
line
):
def
sentcb
(
self
,
line
):
gline
=
gcoder
.
Line
(
line
)
gline
=
gcoder
.
Line
(
line
)
gline
.
parse_coordinates
(
imperial
=
False
)
split_raw
=
gcoder
.
split_line
(
gline
)
gcoder
.
parse_coordinates
(
gline
,
split_raw
,
imperial
=
False
)
if
gline
.
is_move
:
if
gline
.
is_move
:
if
gline
.
z
!=
None
:
if
gline
.
z
!=
None
:
layer
=
gline
.
z
layer
=
gline
.
z
...
@@ -376,13 +377,13 @@ class PronterWindow(MainWindow, pronsole.pronsole):
...
@@ -376,13 +377,13 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self
.
gviz
.
clearhilights
()
self
.
gviz
.
clearhilights
()
wx
.
CallAfter
(
self
.
gviz
.
setlayer
,
layer
)
wx
.
CallAfter
(
self
.
gviz
.
setlayer
,
layer
)
elif
gline
.
command
in
[
"M104"
,
"M109"
]:
elif
gline
.
command
in
[
"M104"
,
"M109"
]:
g
line
.
parse_coordinates
(
imperial
=
False
,
force
=
True
)
g
coder
.
parse_coordinates
(
gline
,
split_raw
,
imperial
=
False
,
force
=
True
)
if
gline
.
s
!=
None
:
if
gline
.
s
!=
None
:
temp
=
gline
.
s
temp
=
gline
.
s
if
self
.
display_gauges
:
wx
.
CallAfter
(
self
.
hottgauge
.
SetTarget
,
temp
)
if
self
.
display_gauges
:
wx
.
CallAfter
(
self
.
hottgauge
.
SetTarget
,
temp
)
if
self
.
display_graph
:
wx
.
CallAfter
(
self
.
graph
.
SetExtruder0TargetTemperature
,
temp
)
if
self
.
display_graph
:
wx
.
CallAfter
(
self
.
graph
.
SetExtruder0TargetTemperature
,
temp
)
elif
gline
.
command
==
"M140"
:
elif
gline
.
command
==
"M140"
:
gline
.
parse_coordinates
(
imperial
=
False
,
force
=
True
)
gline
.
parse_coordinates
(
gline
,
split_raw
,
imperial
=
False
,
force
=
True
)
if
gline
.
s
!=
None
:
if
gline
.
s
!=
None
:
temp
=
gline
.
s
temp
=
gline
.
s
if
self
.
display_gauges
:
wx
.
CallAfter
(
self
.
bedtgauge
.
SetTarget
,
temp
)
if
self
.
display_gauges
:
wx
.
CallAfter
(
self
.
bedtgauge
.
SetTarget
,
temp
)
...
...
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