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
a6a42f64
Commit
a6a42f64
authored
Jun 10, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start refactoring gcview movement. Implement zoom to point.
parent
741e3c8c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
27 deletions
+36
-27
gcview.py
printrun/gcview.py
+36
-27
No files found.
printrun/gcview.py
View file @
a6a42f64
...
...
@@ -63,11 +63,11 @@ class wxGLPanel(wx.Panel):
def
processSizeEvent
(
self
,
event
):
'''Process the resize event.'''
if
(
wx
.
VERSION
>
(
2
,
9
)
and
self
.
canvas
.
IsShownOnScreen
())
or
self
.
canvas
.
GetContext
():
# Make sure the frame is shown before calling SetCurrent.
size
=
self
.
GetClientSize
()
self
.
winsize
=
(
size
.
width
,
size
.
height
)
self
.
width
,
self
.
height
=
size
.
width
,
size
.
height
if
(
wx
.
VERSION
>
(
2
,
9
)
and
self
.
canvas
.
IsShownOnScreen
())
or
self
.
canvas
.
GetContext
():
# Make sure the frame is shown before calling SetCurrent.
self
.
canvas
.
SetCurrent
(
self
.
context
)
self
.
OnReshape
(
size
.
width
,
size
.
height
)
self
.
canvas
.
Refresh
(
False
)
...
...
@@ -97,11 +97,9 @@ class wxGLPanel(wx.Panel):
def
OnInitGL
(
self
):
'''Initialize OpenGL for use in the window.'''
#create a pyglet context for this panel
self
.
mvmat
=
(
GLdouble
*
16
)()
self
.
pygletcontext
=
gl
.
Context
(
gl
.
current_context
)
self
.
pygletcontext
.
canvas
=
self
self
.
pygletcontext
.
set_current
()
self
.
dist
=
1000
#normal gl init
glClearColor
(
0.98
,
0.98
,
0.78
,
1
)
glClearDepth
(
1.0
)
# set depth value to 1
...
...
@@ -121,12 +119,9 @@ class wxGLPanel(wx.Panel):
glViewport
(
0
,
0
,
width
,
height
)
glMatrixMode
(
GL_PROJECTION
)
glLoadIdentity
()
gluPerspective
(
60.
,
width
/
float
(
height
),
.1
,
1000.
)
gluPerspective
(
60.
,
width
/
float
(
height
),
10.0
,
self
.
dist
)
glMatrixMode
(
GL_MODELVIEW
)
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
# Wrap text to the width of the window
if
self
.
GLinitialized
:
...
...
@@ -268,11 +263,8 @@ class GcodeViewPanel(wxGLPanel):
'''called in the middle of ondraw after the buffer has been cleared'''
self
.
create_objects
()
glLoadIdentity
()
glMultMatrixd
(
self
.
mvmat
)
glPushMatrix
()
glTranslatef
(
-
self
.
parent
.
platform
.
width
/
2
,
-
self
.
parent
.
platform
.
depth
/
2
,
0
)
glTranslatef
(
-
self
.
parent
.
platform
.
width
/
2
,
-
self
.
parent
.
platform
.
depth
/
2
,
-
self
.
dist
)
for
obj
in
self
.
parent
.
objects
:
if
not
obj
.
model
or
not
obj
.
model
.
loaded
or
not
obj
.
model
.
initialized
:
...
...
@@ -320,7 +312,6 @@ class GcodeViewPanel(wxGLPanel):
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
glMultMatrixd
(
mat
)
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
elif
event
.
ButtonUp
(
wx
.
MOUSE_BTN_LEFT
):
if
self
.
initpos
is
not
None
:
...
...
@@ -349,7 +340,6 @@ class GcodeViewPanel(wxGLPanel):
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
self
.
initpos
=
None
else
:
event
.
Skip
()
...
...
@@ -377,13 +367,15 @@ class GcodeViewPanel(wxGLPanel):
self
.
parent
.
model
.
num_layers_to_draw
=
new_layer
wx
.
CallAfter
(
self
.
Refresh
)
def
zoom
(
self
,
dist
):
self
.
transv
[
2
]
+=
dist
def
zoom
(
self
,
factor
,
to
=
None
):
glMatrixMode
(
GL_MODELVIEW
)
glLoadIdentity
()
glTranslatef
(
*
self
.
transv
)
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
self
.
mvmat
)
if
to
:
delta_x
=
to
[
0
]
delta_y
=
to
[
1
]
glTranslatef
(
delta_x
,
delta_y
,
0
)
glScalef
(
factor
,
factor
,
1
)
if
to
:
glTranslatef
(
-
delta_x
,
-
delta_y
,
0
)
wx
.
CallAfter
(
self
.
Refresh
)
def
wheel
(
self
,
event
):
...
...
@@ -391,20 +383,37 @@ class GcodeViewPanel(wxGLPanel):
without shift: set max layer
with shift: zoom viewport
"""
z
=
event
.
GetWheelRotation
()
dist
=
10
delta
=
event
.
GetWheelRotation
()
factor
=
1.05
if
event
.
ShiftDown
():
if
not
self
.
parent
.
model
:
return
if
z
>
0
:
if
delta
>
0
:
self
.
layerup
()
else
:
self
.
layerdown
()
return
if
z
>
0
:
self
.
zoom
(
dist
)
x
,
y
=
event
.
GetPositionTuple
()
x
,
y
,
_
=
self
.
mouse_to_3d
(
x
,
y
)
if
delta
>
0
:
self
.
zoom
(
factor
,
(
x
,
y
))
else
:
self
.
zoom
(
-
dist
)
self
.
zoom
(
1
/
factor
,
(
x
,
y
))
def
mouse_to_3d
(
self
,
x
,
y
):
x
=
float
(
x
)
y
=
self
.
height
-
float
(
y
)
pmat
=
(
GLdouble
*
16
)()
mvmat
=
(
GLdouble
*
16
)()
viewport
=
(
GLint
*
4
)()
px
=
(
GLdouble
)()
py
=
(
GLdouble
)()
pz
=
(
GLdouble
)()
glGetIntegerv
(
GL_VIEWPORT
,
viewport
);
glGetDoublev
(
GL_PROJECTION_MATRIX
,
pmat
)
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
mvmat
)
gluUnProject
(
x
,
y
,
1.0
,
mvmat
,
pmat
,
viewport
,
px
,
py
,
pz
)
return
(
px
.
value
,
py
.
value
,
pz
.
value
)
def
keypress
(
self
,
event
):
"""gets keypress events and moves/rotates acive shape"""
...
...
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