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
b6a52146
Commit
b6a52146
authored
Jan 02, 2012
by
kliment
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #145 from AxTheB/export
Refactoring plater.
parents
ca84c816
9e354d85
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
179 additions
and
56 deletions
+179
-56
plater.py
plater.py
+84
-26
stlview.py
stlview.py
+95
-30
No files found.
plater.py
View file @
b6a52146
#!/usr/bin/env python
#!/usr/bin/env python
import
wx
,
time
,
random
,
threading
,
os
,
math
import
wx
,
time
,
random
,
threading
,
os
,
math
import
stltool
import
stltool
glview
=
True
try
:
import
sys
glview
=
False
if
"-nogl"
not
in
sys
.
argv
:
try
:
import
stlview
import
stlview
except
:
glview
=
True
glview
=
False
except
:
pass
def
evalme
(
s
):
def
evalme
(
s
):
return
eval
(
s
[
s
.
find
(
"("
)
+
1
:
s
.
find
(
")"
)])
return
eval
(
s
[
s
.
find
(
"("
)
+
1
:
s
.
find
(
")"
)])
...
@@ -32,6 +39,7 @@ class showstl(wx.Window):
...
@@ -32,6 +39,7 @@ class showstl(wx.Window):
self
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
rot
)
self
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
rot
)
self
.
Bind
(
wx
.
EVT_MOUSE_EVENTS
,
self
.
move
)
self
.
Bind
(
wx
.
EVT_MOUSE_EVENTS
,
self
.
move
)
self
.
Bind
(
wx
.
EVT_PAINT
,
self
.
repaint
)
self
.
Bind
(
wx
.
EVT_PAINT
,
self
.
repaint
)
self
.
Bind
(
wx
.
EVT_KEY_DOWN
,
self
.
keypress
)
#self.s=stltool.stl("sphere.stl").scale([2,1,1])
#self.s=stltool.stl("sphere.stl").scale([2,1,1])
self
.
triggered
=
0
self
.
triggered
=
0
self
.
initpos
=
None
self
.
initpos
=
None
...
@@ -56,35 +64,87 @@ class showstl(wx.Window):
...
@@ -56,35 +64,87 @@ class showstl(wx.Window):
m
.
bitmap
.
SetMask
(
wx
.
Mask
(
m
.
bitmap
,
wx
.
Colour
(
0
,
0
,
0
,
255
)))
m
.
bitmap
.
SetMask
(
wx
.
Mask
(
m
.
bitmap
,
wx
.
Colour
(
0
,
0
,
0
,
255
)))
def
move
(
self
,
event
):
def
move_shape
(
self
,
delta
):
"""moves shape (selected in l, which is list ListBox of shapes)
by an offset specified in tuple delta.
Positive numbers move to (rigt, down)"""
name
=
self
.
parent
.
l
.
GetSelection
()
if
name
==
wx
.
NOT_FOUND
:
return
False
name
=
self
.
parent
.
l
.
GetString
(
name
)
model
=
self
.
parent
.
models
[
name
]
model
.
offsets
=
[
model
.
offsets
[
0
]
+
delta
[
0
],
model
.
offsets
[
1
]
+
delta
[
1
],
model
.
offsets
[
2
]
]
self
.
Refresh
()
return
True
def
move
(
self
,
event
):
if
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
(
self
.
initpos
is
not
None
):
if
(
self
.
initpos
is
not
None
):
i
=
self
.
parent
.
l
.
GetSelection
()
currentpos
=
event
.
GetPositionTuple
()
if
i
!=
wx
.
NOT_FOUND
:
delta
=
(
p
=
event
.
GetPositionTuple
()
0.5
*
(
currentpos
[
0
]
-
self
.
initpos
[
0
]),
#print (p[0]-self.initpos[0]),(p[1]-self.initpos[1])
-
0.5
*
(
currentpos
[
1
]
-
self
.
initpos
[
1
])
t
=
time
.
time
()
)
m
=
self
.
parent
.
models
[
self
.
parent
.
l
.
GetString
(
i
)]
self
.
move_shape
(
delta
)
m
.
offsets
=
[
m
.
offsets
[
0
]
+
0.5
*
(
p
[
0
]
-
self
.
initpos
[
0
]),
m
.
offsets
[
1
]
-
0.5
*
(
p
[
1
]
-
self
.
initpos
[
1
]),
m
.
offsets
[
2
]]
#self.models[self.l.GetItemText(i)]=self.models[self.l.GetItemText(i)].translate([0.5*(p[0]-self.initpos[0]),0.5*(p[1]-self.initpos[1]),0])
#print time.time()-t
self
.
Refresh
()
self
.
Refresh
()
self
.
initpos
=
None
self
.
initpos
=
None
elif
event
.
ButtonDown
(
wx
.
MOUSE_BTN_RIGHT
):
elif
event
.
ButtonDown
(
wx
.
MOUSE_BTN_RIGHT
):
self
.
parent
.
right
(
event
)
self
.
parent
.
right
(
event
)
elif
event
.
Dragging
():
elif
event
.
Dragging
():
if
self
.
initpos
is
None
:
if
self
.
initpos
is
None
:
self
.
initpos
=
event
.
GetPositionTuple
()
self
.
initpos
=
event
.
GetPositionTuple
()
self
.
Refresh
()
self
.
Refresh
()
dc
=
wx
.
ClientDC
(
self
)
dc
=
wx
.
ClientDC
(
self
)
p
=
event
.
GetPositionTuple
()
p
=
event
.
GetPositionTuple
()
dc
.
DrawLine
(
self
.
initpos
[
0
],
self
.
initpos
[
1
],
p
[
0
],
p
[
1
])
dc
.
DrawLine
(
self
.
initpos
[
0
],
self
.
initpos
[
1
],
p
[
0
],
p
[
1
])
#print math.sqrt((p[0]-self.initpos[0])**2+(p[1]-self.initpos[1])**2)
#print math.sqrt((p[0]-self.initpos[0])**2+(p[1]-self.initpos[1])**2)
del
dc
del
dc
else
:
else
:
event
.
Skip
()
event
.
Skip
()
def
rotate_shape
(
self
,
angle
):
"""rotates acive shape
positive angle is clockwise
"""
self
.
i
+=
angle
if
not
self
.
triggered
:
self
.
triggered
=
1
threading
.
Thread
(
target
=
self
.
cr
)
.
start
()
def
keypress
(
self
,
event
):
"""gets keypress events and moves/rotates acive shape"""
keycode
=
event
.
GetKeyCode
()
#print keycode
step
=
5
angle
=
18
if
event
.
ControlDown
():
step
=
1
angle
=
1
#h
if
keycode
==
72
:
self
.
move_shape
((
-
step
,
0
))
#l
if
keycode
==
76
:
self
.
move_shape
((
step
,
0
))
#j
if
keycode
==
75
:
self
.
move_shape
((
0
,
step
))
#k
if
keycode
==
74
:
self
.
move_shape
((
0
,
-
step
))
#[
if
keycode
==
91
:
self
.
rotate_shape
(
-
angle
)
#]
if
keycode
==
93
:
self
.
rotate_shape
(
angle
)
event
.
Skip
()
def
rotateafter
(
self
):
def
rotateafter
(
self
):
if
(
self
.
i
!=
self
.
previ
):
if
(
self
.
i
!=
self
.
previ
):
i
=
self
.
parent
.
l
.
GetSelection
()
i
=
self
.
parent
.
l
.
GetSelection
()
...
@@ -94,6 +154,7 @@ class showstl(wx.Window):
...
@@ -94,6 +154,7 @@ class showstl(wx.Window):
#self.models[self.l.GetItemText(i)].offsets=o
#self.models[self.l.GetItemText(i)].offsets=o
self
.
previ
=
self
.
i
self
.
previ
=
self
.
i
self
.
Refresh
()
self
.
Refresh
()
def
cr
(
self
):
def
cr
(
self
):
time
.
sleep
(
0.01
)
time
.
sleep
(
0.01
)
wx
.
CallAfter
(
self
.
rotateafter
)
wx
.
CallAfter
(
self
.
rotateafter
)
...
@@ -106,12 +167,9 @@ class showstl(wx.Window):
...
@@ -106,12 +167,9 @@ class showstl(wx.Window):
self
.
i
=
0
self
.
i
=
0
self
.
prevsel
=
s
self
.
prevsel
=
s
if
z
<
0
:
if
z
<
0
:
self
.
i
-=
1
self
.
rotate_shape
(
-
1
)
else
:
else
:
self
.
i
+=
1
self
.
rotate_shape
(
1
)
if
not
self
.
triggered
:
self
.
triggered
=
1
threading
.
Thread
(
target
=
self
.
cr
)
.
start
()
def
repaint
(
self
,
event
):
def
repaint
(
self
,
event
):
dc
=
wx
.
PaintDC
(
self
)
dc
=
wx
.
PaintDC
(
self
)
...
...
stlview.py
View file @
b6a52146
...
@@ -445,7 +445,7 @@ class TestGlPanel(GLPanel):
...
@@ -445,7 +445,7 @@ class TestGlPanel(GLPanel):
self
.
initialized
=
1
self
.
initialized
=
1
self
.
canvas
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
wheel
)
self
.
canvas
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
wheel
)
self
.
parent
=
parent
self
.
parent
=
parent
self
.
initp
=
None
self
.
initp
os
=
None
self
.
dist
=
200
self
.
dist
=
200
self
.
bedsize
=
[
200
,
200
]
self
.
bedsize
=
[
200
,
200
]
self
.
transv
=
[
0
,
0
,
-
self
.
dist
]
self
.
transv
=
[
0
,
0
,
-
self
.
dist
]
...
@@ -469,26 +469,49 @@ class TestGlPanel(GLPanel):
...
@@ -469,26 +469,49 @@ class TestGlPanel(GLPanel):
threading
.
Thread
(
target
=
self
.
update
)
.
start
()
threading
.
Thread
(
target
=
self
.
update
)
.
start
()
self
.
initialized
=
0
self
.
initialized
=
0
def
move_shape
(
self
,
delta
):
"""moves shape (selected in l, which is list ListBox of shapes)
by an offset specified in tuple delta.
Positive numbers move to (rigt, down)"""
name
=
self
.
parent
.
l
.
GetSelection
()
if
name
==
wx
.
NOT_FOUND
:
return
False
name
=
self
.
parent
.
l
.
GetString
(
name
)
model
=
self
.
parent
.
models
[
name
]
model
.
offsets
=
[
model
.
offsets
[
0
]
+
delta
[
0
],
model
.
offsets
[
1
]
+
delta
[
1
],
model
.
offsets
[
2
]
]
self
.
Refresh
()
return
True
def
move
(
self
,
event
):
def
move
(
self
,
event
):
"""react to mouse actions:
no mouse: show red mousedrop
LMB: move active object,
with shift rotate viewport
RMB: nothing
with shift move viewport
"""
if
event
.
Dragging
()
and
event
.
LeftIsDown
():
if
event
.
Dragging
()
and
event
.
LeftIsDown
():
if
self
.
initp
==
None
:
if
self
.
initp
os
==
None
:
self
.
initp
=
event
.
GetPositionTuple
()
self
.
initp
os
=
event
.
GetPositionTuple
()
else
:
else
:
if
not
event
.
ShiftDown
():
if
not
event
.
ShiftDown
():
i
=
self
.
parent
.
l
.
GetSelection
()
currentpos
=
event
.
GetPositionTuple
()
if
i
<
0
:
delta
=
(
(
currentpos
[
0
]
-
self
.
initpos
[
0
]),
-
(
currentpos
[
1
]
-
self
.
initpos
[
1
])
)
self
.
move_shape
(
delta
)
self
.
initpos
=
None
return
return
p1
=
list
(
self
.
initp
)
#print self.initpos
p1
[
1
]
*=-
1
p1
=
self
.
initpos
self
.
initp
=
None
self
.
initpos
=
None
p2
=
list
(
event
.
GetPositionTuple
())
p2
[
1
]
*=-
1
m
=
self
.
parent
.
models
[
self
.
parent
.
l
.
GetString
(
i
)]
m
.
offsets
=
map
(
lambda
old
,
new
,
original
:
original
+
(
new
-
old
),
list
(
p1
)
+
[
0
],
list
(
p2
)
+
[
0
],
m
.
offsets
)
return
#print self.initp
p1
=
self
.
initp
self
.
initp
=
None
p2
=
event
.
GetPositionTuple
()
p2
=
event
.
GetPositionTuple
()
sz
=
self
.
GetClientSize
()
sz
=
self
.
GetClientSize
()
p1x
=
(
float
(
p1
[
0
])
-
sz
[
0
]
/
2
)
/
(
sz
[
0
]
/
2
)
p1x
=
(
float
(
p1
[
0
])
-
sz
[
0
]
/
2
)
/
(
sz
[
0
]
/
2
)
...
@@ -511,18 +534,18 @@ class TestGlPanel(GLPanel):
...
@@ -511,18 +534,18 @@ class TestGlPanel(GLPanel):
self
.
rot
=
1
self
.
rot
=
1
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
self
.
initp
is
not
None
:
if
self
.
initp
os
is
not
None
:
self
.
initp
=
None
self
.
initp
os
=
None
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_RIGHT
):
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_RIGHT
):
if
self
.
initp
is
not
None
:
if
self
.
initp
os
is
not
None
:
self
.
initp
=
None
self
.
initp
os
=
None
elif
event
.
Dragging
()
and
event
.
RightIsDown
()
and
event
.
ShiftDown
():
elif
event
.
Dragging
()
and
event
.
RightIsDown
()
and
event
.
ShiftDown
():
if
self
.
initp
is
None
:
if
self
.
initp
os
is
None
:
self
.
initp
=
event
.
GetPositionTuple
()
self
.
initp
os
=
event
.
GetPositionTuple
()
else
:
else
:
p1
=
self
.
initp
p1
=
self
.
initp
os
p2
=
event
.
GetPositionTuple
()
p2
=
event
.
GetPositionTuple
()
sz
=
self
.
GetClientSize
()
sz
=
self
.
GetClientSize
()
p1
=
list
(
p1
)
p1
=
list
(
p1
)
...
@@ -539,7 +562,7 @@ class TestGlPanel(GLPanel):
...
@@ -539,7 +562,7 @@ class TestGlPanel(GLPanel):
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
self
.
rot
=
1
self
.
rot
=
1
self
.
initp
=
None
self
.
initp
os
=
None
else
:
else
:
#mouse is moving without a button press
#mouse is moving without a button press
p
=
event
.
GetPositionTuple
()
p
=
event
.
GetPositionTuple
()
...
@@ -548,9 +571,24 @@ class TestGlPanel(GLPanel):
...
@@ -548,9 +571,24 @@ class TestGlPanel(GLPanel):
v
[
1
]
=
self
.
bedsize
[
1
]
-
v
[
1
]
v
[
1
]
=
self
.
bedsize
[
1
]
-
v
[
1
]
self
.
mousepos
=
v
self
.
mousepos
=
v
def
rotate_shape
(
self
,
angle
):
"""rotates acive shape
positive angle is clockwise
"""
name
=
self
.
parent
.
l
.
GetSelection
()
if
name
==
wx
.
NOT_FOUND
:
return
False
name
=
self
.
parent
.
l
.
GetString
(
name
)
model
=
self
.
parent
.
models
[
name
]
model
.
rot
+=
angle
def
wheel
(
self
,
event
):
def
wheel
(
self
,
event
):
"""react to mouse wheel actions:
rotate object
with shift zoom viewport
"""
z
=
event
.
GetWheelRotation
()
z
=
event
.
GetWheelRotation
()
delta
=
10
angle
=
10
if
not
event
.
ShiftDown
():
if
not
event
.
ShiftDown
():
i
=
self
.
parent
.
l
.
GetSelection
()
i
=
self
.
parent
.
l
.
GetSelection
()
...
@@ -560,17 +598,16 @@ class TestGlPanel(GLPanel):
...
@@ -560,17 +598,16 @@ class TestGlPanel(GLPanel):
except
:
except
:
pass
pass
return
return
m
=
self
.
parent
.
models
[
self
.
parent
.
l
.
GetString
(
i
)]
if
z
>
0
:
if
z
>
0
:
m
.
rot
+=
delta
/
2
self
.
rotate_shape
(
angle
/
2
)
else
:
else
:
m
.
rot
-=
delta
/
2
self
.
rotate_shape
(
-
angle
/
2
)
return
return
if
z
>
0
:
if
z
>
0
:
self
.
transv
[
2
]
+=
delta
self
.
transv
[
2
]
+=
angle
else
:
else
:
self
.
transv
[
2
]
-=
delta
self
.
transv
[
2
]
-=
angle
glLoadIdentity
()
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
glTranslatef
(
*
self
.
transv
)
...
@@ -579,6 +616,34 @@ class TestGlPanel(GLPanel):
...
@@ -579,6 +616,34 @@ class TestGlPanel(GLPanel):
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
self
.
rot
=
1
self
.
rot
=
1
def
keypress
(
self
,
event
):
"""gets keypress events and moves/rotates acive shape"""
keycode
=
event
.
GetKeyCode
()
print
keycode
step
=
5
angle
=
18
if
event
.
ControlDown
():
step
=
1
angle
=
1
#h
if
keycode
==
72
:
self
.
move_shape
((
-
step
,
0
))
#l
if
keycode
==
76
:
self
.
move_shape
((
step
,
0
))
#j
if
keycode
==
75
:
self
.
move_shape
((
0
,
step
))
#k
if
keycode
==
74
:
self
.
move_shape
((
0
,
-
step
))
#[
if
keycode
==
91
:
self
.
rotate_shape
(
-
angle
)
#]
if
keycode
==
93
:
self
.
rotate_shape
(
angle
)
event
.
Skip
()
def
update
(
self
):
def
update
(
self
):
while
(
1
):
while
(
1
):
...
...
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