Commit a6a42f64 authored by Guillaume Seguin's avatar Guillaume Seguin

Start refactoring gcview movement. Implement zoom to point.

parent 741e3c8c
...@@ -63,11 +63,11 @@ class wxGLPanel(wx.Panel): ...@@ -63,11 +63,11 @@ class wxGLPanel(wx.Panel):
def processSizeEvent(self, event): def processSizeEvent(self, event):
'''Process the resize event.''' '''Process the resize event.'''
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(): if (wx.VERSION > (2,9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext():
# Make sure the frame is shown before calling SetCurrent. # 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
self.canvas.SetCurrent(self.context) self.canvas.SetCurrent(self.context)
self.OnReshape(size.width, size.height) self.OnReshape(size.width, size.height)
self.canvas.Refresh(False) self.canvas.Refresh(False)
...@@ -97,11 +97,9 @@ class wxGLPanel(wx.Panel): ...@@ -97,11 +97,9 @@ class wxGLPanel(wx.Panel):
def OnInitGL(self): def OnInitGL(self):
'''Initialize OpenGL for use in the window.''' '''Initialize OpenGL for use in the window.'''
#create a pyglet context for this panel #create a pyglet context for this panel
self.mvmat = (GLdouble * 16)()
self.pygletcontext = gl.Context(gl.current_context) self.pygletcontext = gl.Context(gl.current_context)
self.pygletcontext.canvas = self self.pygletcontext.canvas = self
self.pygletcontext.set_current() self.pygletcontext.set_current()
self.dist = 1000
#normal gl init #normal gl init
glClearColor(0.98, 0.98, 0.78, 1) glClearColor(0.98, 0.98, 0.78, 1)
glClearDepth(1.0) # set depth value to 1 glClearDepth(1.0) # set depth value to 1
...@@ -121,12 +119,9 @@ class wxGLPanel(wx.Panel): ...@@ -121,12 +119,9 @@ class wxGLPanel(wx.Panel):
glViewport(0, 0, width, height) glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION) glMatrixMode(GL_PROJECTION)
glLoadIdentity() glLoadIdentity()
gluPerspective(60., width / float(height), .1, 1000.) gluPerspective(60., width / float(height), 10.0, self.dist)
glMatrixMode(GL_MODELVIEW) glMatrixMode(GL_MODELVIEW)
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv)
glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
# Wrap text to the width of the window # Wrap text to the width of the window
if self.GLinitialized: if self.GLinitialized:
...@@ -267,12 +262,9 @@ class GcodeViewPanel(wxGLPanel): ...@@ -267,12 +262,9 @@ class GcodeViewPanel(wxGLPanel):
def draw_objects(self): def draw_objects(self):
'''called in the middle of ondraw after the buffer has been cleared''' '''called in the middle of ondraw after the buffer has been cleared'''
self.create_objects() self.create_objects()
glLoadIdentity()
glMultMatrixd(self.mvmat)
glPushMatrix() 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: for obj in self.parent.objects:
if not obj.model or not obj.model.loaded or not obj.model.initialized: if not obj.model or not obj.model.loaded or not obj.model.initialized:
...@@ -320,7 +312,6 @@ class GcodeViewPanel(wxGLPanel): ...@@ -320,7 +312,6 @@ class GcodeViewPanel(wxGLPanel):
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv) glTranslatef(*self.transv)
glMultMatrixd(mat) glMultMatrixd(mat)
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
elif event.ButtonUp(wx.MOUSE_BTN_LEFT): elif event.ButtonUp(wx.MOUSE_BTN_LEFT):
if self.initpos is not None: if self.initpos is not None:
...@@ -349,7 +340,6 @@ class GcodeViewPanel(wxGLPanel): ...@@ -349,7 +340,6 @@ class GcodeViewPanel(wxGLPanel):
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv) glTranslatef(*self.transv)
glMultMatrixd(build_rotmatrix(self.basequat)) glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat)
self.initpos = None self.initpos = None
else: else:
event.Skip() event.Skip()
...@@ -377,13 +367,15 @@ class GcodeViewPanel(wxGLPanel): ...@@ -377,13 +367,15 @@ class GcodeViewPanel(wxGLPanel):
self.parent.model.num_layers_to_draw = new_layer self.parent.model.num_layers_to_draw = new_layer
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def zoom(self, dist): def zoom(self, factor, to = None):
self.transv[2] += dist
glMatrixMode(GL_MODELVIEW) glMatrixMode(GL_MODELVIEW)
glLoadIdentity() if to:
glTranslatef(*self.transv) delta_x = to[0]
glMultMatrixd(build_rotmatrix(self.basequat)) delta_y = to[1]
glGetDoublev(GL_MODELVIEW_MATRIX, self.mvmat) glTranslatef(delta_x, delta_y, 0)
glScalef(factor, factor, 1)
if to:
glTranslatef(-delta_x, -delta_y, 0)
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def wheel(self, event): def wheel(self, event):
...@@ -391,20 +383,37 @@ class GcodeViewPanel(wxGLPanel): ...@@ -391,20 +383,37 @@ class GcodeViewPanel(wxGLPanel):
without shift: set max layer without shift: set max layer
with shift: zoom viewport with shift: zoom viewport
""" """
z = event.GetWheelRotation() delta = event.GetWheelRotation()
dist = 10 factor = 1.05
if event.ShiftDown(): if event.ShiftDown():
if not self.parent.model: if not self.parent.model:
return return
if z > 0: if delta > 0:
self.layerup() self.layerup()
else: else:
self.layerdown() self.layerdown()
return return
if z > 0: x, y = event.GetPositionTuple()
self.zoom(dist) x, y, _ = self.mouse_to_3d(x, y)
if delta > 0:
self.zoom(factor, (x, y))
else: 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): def keypress(self, event):
"""gets keypress events and moves/rotates acive shape""" """gets keypress events and moves/rotates acive shape"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment