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
Hide 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
import
wx
,
time
,
random
,
threading
,
os
,
math
import
stltool
glview
=
True
try
:
import
stlview
except
:
glview
=
False
import
sys
glview
=
False
if
"-nogl"
not
in
sys
.
argv
:
try
:
import
stlview
glview
=
True
except
:
pass
def
evalme
(
s
):
return
eval
(
s
[
s
.
find
(
"("
)
+
1
:
s
.
find
(
")"
)])
...
...
@@ -32,6 +39,7 @@ class showstl(wx.Window):
self
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
rot
)
self
.
Bind
(
wx
.
EVT_MOUSE_EVENTS
,
self
.
move
)
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
.
triggered
=
0
self
.
initpos
=
None
...
...
@@ -56,35 +64,87 @@ class showstl(wx.Window):
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
(
self
.
initpos
is
not
None
):
i
=
self
.
parent
.
l
.
GetSelection
()
if
i
!=
wx
.
NOT_FOUND
:
p
=
event
.
GetPositionTuple
()
#print (p[0]-self.initpos[0]),(p[1]-self.initpos[1])
t
=
time
.
time
()
m
=
self
.
parent
.
models
[
self
.
parent
.
l
.
GetString
(
i
)]
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
currentpos
=
event
.
GetPositionTuple
()
delta
=
(
0.5
*
(
currentpos
[
0
]
-
self
.
initpos
[
0
]),
-
0.5
*
(
currentpos
[
1
]
-
self
.
initpos
[
1
])
)
self
.
move_shape
(
delta
)
self
.
Refresh
()
self
.
initpos
=
None
self
.
initpos
=
None
elif
event
.
ButtonDown
(
wx
.
MOUSE_BTN_RIGHT
):
self
.
parent
.
right
(
event
)
elif
event
.
Dragging
():
if
self
.
initpos
is
None
:
self
.
initpos
=
event
.
GetPositionTuple
()
self
.
initpos
=
event
.
GetPositionTuple
()
self
.
Refresh
()
dc
=
wx
.
ClientDC
(
self
)
p
=
event
.
GetPositionTuple
()
dc
.
DrawLine
(
self
.
initpos
[
0
],
self
.
initpos
[
1
],
p
[
0
],
p
[
1
])
dc
=
wx
.
ClientDC
(
self
)
p
=
event
.
GetPositionTuple
()
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)
del
dc
else
:
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
):
if
(
self
.
i
!=
self
.
previ
):
i
=
self
.
parent
.
l
.
GetSelection
()
...
...
@@ -94,6 +154,7 @@ class showstl(wx.Window):
#self.models[self.l.GetItemText(i)].offsets=o
self
.
previ
=
self
.
i
self
.
Refresh
()
def
cr
(
self
):
time
.
sleep
(
0.01
)
wx
.
CallAfter
(
self
.
rotateafter
)
...
...
@@ -106,12 +167,9 @@ class showstl(wx.Window):
self
.
i
=
0
self
.
prevsel
=
s
if
z
<
0
:
self
.
i
-=
1
self
.
rotate_shape
(
-
1
)
else
:
self
.
i
+=
1
if
not
self
.
triggered
:
self
.
triggered
=
1
threading
.
Thread
(
target
=
self
.
cr
)
.
start
()
self
.
rotate_shape
(
1
)
def
repaint
(
self
,
event
):
dc
=
wx
.
PaintDC
(
self
)
...
...
stlview.py
View file @
b6a52146
...
...
@@ -445,7 +445,7 @@ class TestGlPanel(GLPanel):
self
.
initialized
=
1
self
.
canvas
.
Bind
(
wx
.
EVT_MOUSEWHEEL
,
self
.
wheel
)
self
.
parent
=
parent
self
.
initp
=
None
self
.
initp
os
=
None
self
.
dist
=
200
self
.
bedsize
=
[
200
,
200
]
self
.
transv
=
[
0
,
0
,
-
self
.
dist
]
...
...
@@ -469,26 +469,49 @@ class TestGlPanel(GLPanel):
threading
.
Thread
(
target
=
self
.
update
)
.
start
()
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
):
"""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
self
.
initp
==
None
:
self
.
initp
=
event
.
GetPositionTuple
()
if
self
.
initp
os
==
None
:
self
.
initp
os
=
event
.
GetPositionTuple
()
else
:
if
not
event
.
ShiftDown
():
i
=
self
.
parent
.
l
.
GetSelection
()
if
i
<
0
:
return
p1
=
list
(
self
.
initp
)
p1
[
1
]
*=-
1
self
.
initp
=
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
)
currentpos
=
event
.
GetPositionTuple
()
delta
=
(
(
currentpos
[
0
]
-
self
.
initpos
[
0
]),
-
(
currentpos
[
1
]
-
self
.
initpos
[
1
])
)
self
.
move_shape
(
delta
)
self
.
initpos
=
None
return
#print self.initp
p1
=
self
.
initp
self
.
initp
=
None
#print self.initp
os
p1
=
self
.
initp
os
self
.
initp
os
=
None
p2
=
event
.
GetPositionTuple
()
sz
=
self
.
GetClientSize
()
p1x
=
(
float
(
p1
[
0
])
-
sz
[
0
]
/
2
)
/
(
sz
[
0
]
/
2
)
...
...
@@ -511,18 +534,18 @@ class TestGlPanel(GLPanel):
self
.
rot
=
1
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
self
.
initp
is
not
None
:
self
.
initp
=
None
if
self
.
initp
os
is
not
None
:
self
.
initp
os
=
None
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_RIGHT
):
if
self
.
initp
is
not
None
:
self
.
initp
=
None
if
self
.
initp
os
is
not
None
:
self
.
initp
os
=
None
elif
event
.
Dragging
()
and
event
.
RightIsDown
()
and
event
.
ShiftDown
():
if
self
.
initp
is
None
:
self
.
initp
=
event
.
GetPositionTuple
()
if
self
.
initp
os
is
None
:
self
.
initp
os
=
event
.
GetPositionTuple
()
else
:
p1
=
self
.
initp
p1
=
self
.
initp
os
p2
=
event
.
GetPositionTuple
()
sz
=
self
.
GetClientSize
()
p1
=
list
(
p1
)
...
...
@@ -539,7 +562,7 @@ class TestGlPanel(GLPanel):
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
self
.
rot
=
1
self
.
initp
=
None
self
.
initp
os
=
None
else
:
#mouse is moving without a button press
p
=
event
.
GetPositionTuple
()
...
...
@@ -548,9 +571,24 @@ class TestGlPanel(GLPanel):
v
[
1
]
=
self
.
bedsize
[
1
]
-
v
[
1
]
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
):
"""react to mouse wheel actions:
rotate object
with shift zoom viewport
"""
z
=
event
.
GetWheelRotation
()
delta
=
10
angle
=
10
if
not
event
.
ShiftDown
():
i
=
self
.
parent
.
l
.
GetSelection
()
...
...
@@ -560,17 +598,16 @@ class TestGlPanel(GLPanel):
except
:
pass
return
m
=
self
.
parent
.
models
[
self
.
parent
.
l
.
GetString
(
i
)]
if
z
>
0
:
m
.
rot
+=
delta
/
2
self
.
rotate_shape
(
angle
/
2
)
else
:
m
.
rot
-=
delta
/
2
self
.
rotate_shape
(
-
angle
/
2
)
return
if
z
>
0
:
self
.
transv
[
2
]
+=
delta
self
.
transv
[
2
]
+=
angle
else
:
self
.
transv
[
2
]
-=
delta
self
.
transv
[
2
]
-=
angle
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
...
...
@@ -579,6 +616,34 @@ class TestGlPanel(GLPanel):
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
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
):
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