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
b9d8fac7
Commit
b9d8fac7
authored
Jan 27, 2012
by
Václav 'Ax' Hůla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
line rendering in separate thread
parent
afc3abb4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
38 deletions
+97
-38
gcview.py
gcview.py
+97
-38
No files found.
gcview.py
100644 → 100755
View file @
b9d8fac7
...
@@ -13,6 +13,8 @@ from pyglet.gl import *
...
@@ -13,6 +13,8 @@ from pyglet.gl import *
import
stltool
import
stltool
import
threading
class
GLPanel
(
wx
.
Panel
):
class
GLPanel
(
wx
.
Panel
):
'''A simple class for using OpenGL with wxPython.'''
'''A simple class for using OpenGL with wxPython.'''
...
@@ -241,7 +243,7 @@ class gcline(object):
...
@@ -241,7 +243,7 @@ class gcline(object):
self
.
calc_len
()
self
.
calc_len
()
def
__str__
(
self
):
def
__str__
(
self
):
return
u"line from
%
s,
%
s,
%
s to
%
s,
%
s,
%
s with extrusion ratio
%
s and feedrate
%
n
\n
%
s"
%
(
return
u"line from
%
s,
%
s,
%
s to
%
s,
%
s,
%
s with extrusion ratio
%
s and feedrate
%
s
\n
%
s"
%
(
self
.
prev_gcline
.
x
,
self
.
prev_gcline
.
x
,
self
.
prev_gcline
.
y
,
self
.
prev_gcline
.
y
,
self
.
prev_gcline
.
z
,
self
.
prev_gcline
.
z
,
...
@@ -316,46 +318,62 @@ class gcline(object):
...
@@ -316,46 +318,62 @@ class gcline(object):
def
float_from_line
(
axe
,
line
):
def
float_from_line
(
axe
,
line
):
return
float
(
line
.
split
(
axe
)[
1
]
.
split
(
" "
)[
0
])
return
float
(
line
.
split
(
axe
)[
1
]
.
split
(
" "
)[
0
])
class
gcThreadRenderer
(
threading
.
Thread
):
def
__init__
(
self
,
gcview
,
lines
):
threading
.
Thread
.
__init__
(
self
)
self
.
gcview
=
gcview
self
.
lines
=
lines
print
"q init"
def
run
(
self
):
for
line
in
self
.
lines
:
layer_name
=
line
.
z
if
line
.
z
not
in
self
.
gcview
.
layers
:
self
.
gcview
.
layers
[
line
.
z
]
=
pyglet
.
graphics
.
Batch
()
self
.
gcview
.
layerlist
=
self
.
gcview
.
layers
.
keys
()
self
.
gcview
.
layerlist
.
sort
()
self
.
gcview
.
layers
[
line
.
z
]
.
add
(
2
,
GL_LINES
,
None
,
(
"v3f"
,
line
.
glline
()),
(
"c3B"
,
line
.
glcolor
(
self
.
gcview
.
upper_limit
,
self
.
gcview
.
lower_limit
,
self
.
gcview
.
max_feedrate
)))
self
.
gcview
.
t2
=
time
.
time
()
print
"Rendered lines in
%
fs"
%
(
self
.
gcview
.
t2
-
self
.
gcview
.
t1
)
class
gcview
(
object
):
class
gcview
(
object
):
"""gcode visualiser
"""gcode visualiser
Holds opengl objects for all layers
Holds opengl objects for all layers
"""
"""
def
__init__
(
self
,
lines
,
batch
,
w
=
0.5
,
h
=
0.5
):
def
__init__
(
self
,
lines
,
batch
,
w
=
0.5
,
h
=
0.5
):
if
len
(
lines
)
==
0
:
return
print
"Loading
%
s lines"
%
(
len
(
lines
))
#End pos of previous mode
#End pos of previous mode
self
.
prev
=
gcpoint
()
self
.
prev
=
gcpoint
()
# Correction for G92 moves
# Correction for G92 moves
self
.
delta
=
[
0
,
0
,
0
,
0
]
self
.
delta
=
[
0
,
0
,
0
,
0
]
self
.
layers
=
{}
self
.
layers
=
{}
t0
=
time
.
time
()
self
.
t0
=
time
.
time
()
self
.
lastf
=
0
self
.
lastf
=
0
lines
=
[
self
.
transform
(
i
)
for
i
in
lines
]
lines
=
[
self
.
transform
(
i
)
for
i
in
lines
]
lines
=
[
i
for
i
in
lines
if
i
is
not
None
]
lines
=
[
i
for
i
in
lines
if
i
is
not
None
]
t1
=
time
.
time
()
self
.
t1
=
time
.
time
()
print
"transformed
%
s lines in
%
fs"
%
(
len
(
lines
),
t1
-
t0
)
print
"transformed
%
s lines in
%
fs"
%
(
len
(
lines
),
self
.
t1
-
self
.
t0
)
upper_limit
=
0
self
.
upper_limit
=
0
lower_limit
=
None
self
.
lower_limit
=
None
max_feedrate
=
0
self
.
max_feedrate
=
0
for
line
in
lines
:
for
line
in
lines
:
if
line
.
extrusion_ratio
and
line
.
length
>
0.005
:
#lines shorter than 0.003 can have large extrusion ratio
if
line
.
extrusion_ratio
and
line
.
length
>
0.005
:
#lines shorter than 0.003 can have large extrusion ratio
if
line
.
extrusion_ratio
>
upper_limit
:
if
line
.
extrusion_ratio
>
self
.
upper_limit
:
upper_limit
=
line
.
extrusion_ratio
self
.
upper_limit
=
line
.
extrusion_ratio
if
lower_limit
is
None
or
line
.
extrusion_ratio
<
lower_limit
:
if
self
.
lower_limit
is
None
or
line
.
extrusion_ratio
<
self
.
lower_limit
:
lower_limit
=
line
.
extrusion_ratio
self
.
lower_limit
=
line
.
extrusion_ratio
if
line
.
f
>
max_feedrate
:
if
line
.
f
>
self
.
max_feedrate
:
max_feedrate
=
line
.
f
self
.
max_feedrate
=
line
.
f
#print upper_limit, lower_limit
#print upper_limit, lower_limit
#self.render_gl(lines)
q
=
gcThreadRenderer
(
self
,
lines
)
q
.
setDaemon
(
True
)
q
.
start
()
layertemp
=
{}
counter
=
0
for
line
in
lines
:
layer_name
=
line
.
z
if
line
.
z
not
in
self
.
layers
:
self
.
layers
[
line
.
z
]
=
pyglet
.
graphics
.
Batch
()
self
.
layers
[
line
.
z
]
.
add
(
2
,
GL_LINES
,
None
,
(
"v3f"
,
line
.
glline
()),
(
"c3B"
,
line
.
glcolor
(
upper_limit
,
lower_limit
,
max_feedrate
)))
self
.
layerlist
=
self
.
layers
.
keys
()
self
.
layerlist
.
sort
()
t2
=
time
.
time
()
print
"Rendered lines in
%
fs"
%
(
t2
-
t1
)
def
transform
(
self
,
line
):
def
transform
(
self
,
line
):
"""transforms line of gcode into gcline object (or None if its not move)
"""transforms line of gcode into gcline object (or None if its not move)
...
@@ -846,8 +864,34 @@ class TestGlPanel(GLPanel):
...
@@ -846,8 +864,34 @@ class TestGlPanel(GLPanel):
glScalef
(
*
i
.
scale
)
glScalef
(
*
i
.
scale
)
#glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.93, 0.37, 0.25, 1))
#glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.93, 0.37, 0.25, 1))
glEnable
(
GL_COLOR_MATERIAL
)
glEnable
(
GL_COLOR_MATERIAL
)
glLineWidth
(
0.7
)
[
i
.
gc
.
layers
[
j
]
.
draw
()
for
j
in
i
.
gc
.
layerlist
if
j
<
i
.
curlayer
]
if
i
.
curlayer
==
-
1
:
# curlayer == -1 means we are over the top.
glLineWidth
(
0.8
)
[
i
.
gc
.
layers
[
j
]
.
draw
()
for
j
in
i
.
gc
.
layerlist
]
else
:
glLineWidth
(
0.6
)
tmpindex
=
i
.
gc
.
layerlist
.
index
(
i
.
curlayer
)
if
tmpindex
>=
5
:
thin_layer
=
i
.
gc
.
layerlist
[
tmpindex
-
5
]
[
i
.
gc
.
layers
[
j
]
.
draw
()
for
j
in
i
.
gc
.
layerlist
if
j
<=
thin_layer
]
if
tmpindex
>
4
:
glLineWidth
(
0.9
)
i
.
gc
.
layers
[
i
.
gc
.
layerlist
[
tmpindex
-
4
]]
.
draw
()
if
tmpindex
>
3
:
glLineWidth
(
1.1
)
i
.
gc
.
layers
[
i
.
gc
.
layerlist
[
tmpindex
-
3
]]
.
draw
()
if
tmpindex
>
2
:
glLineWidth
(
1.3
)
i
.
gc
.
layers
[
i
.
gc
.
layerlist
[
tmpindex
-
2
]]
.
draw
()
if
tmpindex
>
1
:
glLineWidth
(
2.2
)
i
.
gc
.
layers
[
i
.
gc
.
layerlist
[
tmpindex
-
1
]]
.
draw
()
glLineWidth
(
3.5
)
glLineWidth
(
3.5
)
i
.
gc
.
layers
[
i
.
curlayer
]
.
draw
()
i
.
gc
.
layers
[
i
.
curlayer
]
.
draw
()
...
@@ -903,16 +947,31 @@ class GCFrame(wx.Frame):
...
@@ -903,16 +947,31 @@ class GCFrame(wx.Frame):
def
setlayerindex
(
self
,
z
):
def
setlayerindex
(
self
,
z
):
m
=
self
.
models
[
"GCODE"
]
m
=
self
.
models
[
"GCODE"
]
try
:
mlk
=
m
.
gc
.
layerlist
mlk
=
m
.
gc
.
layerlist
if
z
>
0
and
self
.
modelindex
<
len
(
mlk
)
-
1
:
except
:
mlk
=
[]
if
z
is
None
:
self
.
modelindex
=
-
1
elif
z
>
0
:
if
self
.
modelindex
<
len
(
mlk
)
-
1
:
if
self
.
modelindex
>
-
1
:
self
.
modelindex
+=
1
self
.
modelindex
+=
1
elif
z
<
0
and
self
.
modelindex
>
0
:
else
:
self
.
modelindex
=
-
1
elif
z
<
0
:
if
self
.
modelindex
>
0
:
self
.
modelindex
-=
1
self
.
modelindex
-=
1
elif
z
is
None
:
elif
self
.
modelindex
==
-
1
:
self
.
modelindex
=
len
(
mlk
)
-
1
self
.
modelindex
=
len
(
mlk
)
if
self
.
modelindex
>=
0
:
m
.
curlayer
=
mlk
[
self
.
modelindex
]
m
.
curlayer
=
mlk
[
self
.
modelindex
]
wx
.
CallAfter
(
self
.
SetTitle
,
"Gcode view, shift to move. Layer
%
d, Z =
%
f"
%
(
self
.
modelindex
,
m
.
curlayer
))
wx
.
CallAfter
(
self
.
SetTitle
,
"Gcode view, shift to move. Layer
%
d/
%
d, Z =
%
f"
%
(
self
.
modelindex
,
len
(
mlk
),
m
.
curlayer
))
else
:
m
.
curlayer
=
-
1
wx
.
CallAfter
(
self
.
SetTitle
,
"Gcode view, shift to move view, mousewheel to set layer"
)
def
main
():
def
main
():
...
...
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