Commit e2359ce6 authored by D1plo1d's avatar D1plo1d

Merge branch 'experimental' of github.com:kliment/Printrun into experimental

parents ab95356d 46c2805d
......@@ -125,17 +125,21 @@ class wxGLPanel(wx.Panel):
glOrtho(-width / 2, width / 2, -height / 2, height / 2, 0.1, 3 * self.dist)
else:
gluPerspective(60., float(width) / height, 10.0, 3 * self.dist)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
if self.orthographic:
ratio = 0.9 * float(min(self.width, self.height)) / self.dist
glScalef(ratio, ratio, 1)
self.reset_mview(0.9)
# Wrap text to the width of the window
if self.GLinitialized:
self.pygletcontext.set_current()
self.update_object_resize()
def reset_mview(self, factor):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
if self.orthographic:
ratio = factor * float(min(self.width, self.height)) / self.dist
glScalef(ratio, ratio, 1)
def OnDraw(self, *args, **kwargs):
"""Draw the window."""
self.pygletcontext.set_current()
......@@ -251,8 +255,10 @@ class GcodeViewPanel(wxGLPanel):
self.initpos = None
if build_dimensions:
self.dist = max(build_dimensions[0], build_dimensions[1])
self.build_dimensions = build_dimensions
else:
self.dist = 200
self.build_dimensions = [200, 200, 100, 0, 0, 0]
self.basequat = [0, 0, 0, 1]
self.mousepos = [0, 0]
......@@ -273,7 +279,8 @@ class GcodeViewPanel(wxGLPanel):
glPushMatrix()
glTranslatef(0, 0, -self.dist) # Move back
glMultMatrixd(build_rotmatrix(self.basequat)) # Rotate according to trackball
glTranslatef(-self.parent.platform.width/2, -self.parent.platform.depth/2, 0) # Move origin to bottom left of platform
glTranslatef(- self.build_dimensions[3] - self.parent.platform.width/2,
- self.build_dimensions[4] - self.parent.platform.depth/2, 0) # Move origin to bottom left of platform
for obj in self.parent.objects:
if not obj.model or not obj.model.loaded or not obj.model.initialized:
......@@ -415,6 +422,20 @@ class GcodeViewPanel(wxGLPanel):
gluUnProject(x, y, 1.0, mvmat, pmat, viewport, px, py, pz)
return (px.value, py.value, pz.value)
def fit(self):
if not self.parent.model or not self.parent.model.loaded:
return
dims = self.parent.model.dims
self.reset_mview(1.0)
center_x = (dims[0][0] + dims[0][1]) / 2
center_y = (dims[1][0] + dims[1][1]) / 2
center_x = self.build_dimensions[0] / 2 - center_x
center_y = self.build_dimensions[1] / 2 - center_y
if self.orthographic:
ratio = float(self.dist) / max(dims[0][2], dims[1][2])
glScalef(ratio, ratio, 1)
glTranslatef(center_x, center_y, 0)
def keypress(self, event):
"""gets keypress events and moves/rotates acive shape"""
step = 1.1
......@@ -424,6 +445,8 @@ class GcodeViewPanel(wxGLPanel):
kdo = [68, 317] # Down Keys
kzi = [wx.WXK_PAGEDOWN, 388, 316, 61] # Zoom In Keys
kzo = [wx.WXK_PAGEUP, 390, 314, 45] # Zoom Out Keys
kfit = [70] # Fit to print keys
kreset = [82] # Reset keys
key = event.GetKeyCode()
if key in kup:
self.layerup()
......@@ -434,6 +457,11 @@ class GcodeViewPanel(wxGLPanel):
self.zoom(step, (x, y))
if key in kzo:
self.zoom(1 / step, (x, y))
if key in kfit:
self.fit()
if key in kreset:
self.reset_mview(0.9)
self.basequat = [0, 0, 0, 1]
event.Skip()
wx.CallAfter(self.Refresh)
......
......@@ -249,6 +249,10 @@ class GcodeModel(Model):
def load_data(self, model_data, callback=None):
t_start = time.time()
self.dims = ((model_data.xmin,model_data.xmax,model_data.width),
(model_data.ymin,model_data.ymax,model_data.depth),
(model_data.zmin,model_data.zmax,model_data.height))
vertex_list = []
color_list = []
self.layer_stops = [0]
......
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