Commit 74df4e20 authored by Guillaume Seguin's avatar Guillaume Seguin

Rework gcview a little bit

parent 6f7c26f5
...@@ -189,6 +189,7 @@ class GcodeViewPanel(wxGLPanel): ...@@ -189,6 +189,7 @@ class GcodeViewPanel(wxGLPanel):
def fit(self): def fit(self):
if not self.parent.model or not self.parent.model.loaded: if not self.parent.model or not self.parent.model.loaded:
return return
self.canvas.SetCurrent(self.context)
dims = self.parent.model.dims dims = self.parent.model.dims
self.reset_mview(1.0) self.reset_mview(1.0)
center_x = (dims[0][0] + dims[0][1]) / 2 center_x = (dims[0][0] + dims[0][1]) / 2
...@@ -199,6 +200,7 @@ class GcodeViewPanel(wxGLPanel): ...@@ -199,6 +200,7 @@ class GcodeViewPanel(wxGLPanel):
ratio = float(self.dist) / max(dims[0][2], dims[1][2]) ratio = float(self.dist) / max(dims[0][2], dims[1][2])
glScalef(ratio, ratio, 1) glScalef(ratio, ratio, 1)
glTranslatef(center_x, center_y, 0) glTranslatef(center_x, center_y, 0)
wx.CallAfter(self.Refresh)
def keypress(self, event): def keypress(self, event):
"""gets keypress events and moves/rotates acive shape""" """gets keypress events and moves/rotates acive shape"""
...@@ -219,9 +221,9 @@ class GcodeViewPanel(wxGLPanel): ...@@ -219,9 +221,9 @@ class GcodeViewPanel(wxGLPanel):
self.layerdown() self.layerdown()
x, y, _ = self.mouse_to_3d(self.width / 2, self.height / 2) x, y, _ = self.mouse_to_3d(self.width / 2, self.height / 2)
if key in kzi: if key in kzi:
self.zoom(step, (x, y)) self.zoom_to_center(step)
if key in kzo: if key in kzo:
self.zoom(1 / step, (x, y)) self.zoom_to_center(1 / step)
if key in kfit: if key in kfit:
self.fit() self.fit()
if key in kshowcurrent: if key in kshowcurrent:
...@@ -229,9 +231,13 @@ class GcodeViewPanel(wxGLPanel): ...@@ -229,9 +231,13 @@ class GcodeViewPanel(wxGLPanel):
return return
self.parent.model.only_current = not self.parent.model.only_current self.parent.model.only_current = not self.parent.model.only_current
if key in kreset: if key in kreset:
self.reset_mview(0.9) self.resetview()
self.basequat = [0, 0, 0, 1]
event.Skip() event.Skip()
def resetview(self):
self.canvas.SetCurrent(self.context)
self.reset_mview(0.9)
self.basequat = [0, 0, 0, 1]
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
class GCObject(object): class GCObject(object):
......
...@@ -199,3 +199,8 @@ class wxGLPanel(wx.Panel): ...@@ -199,3 +199,8 @@ class wxGLPanel(wx.Panel):
if to: if to:
glTranslatef(-delta_x, -delta_y, 0) glTranslatef(-delta_x, -delta_y, 0)
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def zoom_to_center(self, factor):
self.canvas.SetCurrent(self.context)
x, y, _ = self.mouse_to_3d(self.width / 2, self.height / 2)
self.zoom(factor, (x, y))
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