from Cura.gui.util import opengl
from Cura.gui.util import openglGui
-class anim(object):
- def __init__(self, start, end, runTime):
- self._start = start
- self._end = end
- self._startTime = time.time()
- self._runTime = runTime
-
- def isDone(self):
- return time.time() > self._startTime + self._runTime
-
- def getPosition(self):
- if self.isDone():
- return self._end
- f = (time.time() - self._startTime) / self._runTime
- ts = f*f
- tc = f*f*f
- #f = 6*tc*ts + -15*ts*ts + 10*tc
- f = tc + -3*ts + 3*f
- return self._start + (self._end - self._start) * f
-
class SceneView(openglGui.glGuiPanel):
def __init__(self, parent):
super(SceneView, self).__init__(parent)
self.OnToolSelect(0)
self.updateProfileToControls()
- wx.EVT_IDLE(self, self.OnIdle)
def ShowLoadModel(self, button):
if button == 1:
shutil.copy(self._slicer.getGCodeFilename(), filename)
- def OnIdle(self, e):
- if self._animView is not None or self._animZoom is not None:
- self.Refresh()
- return
- for obj in self._scene.objects():
- if obj._loadAnim is not None:
- self.Refresh()
- return
-
def OnToolSelect(self, button):
if self.rotateToolButton.getSelected():
self.tool = previewTools.toolRotate(self)
traceback.print_exc()
else:
for obj in objList:
- obj._loadAnim = anim(1, 0, 1.5)
+ obj._loadAnim = openglGui.animation(self, 1, 0, 1.5)
self._scene.add(obj)
self._scene.centerAll()
self._selectObject(obj)
self.updateProfileToControls()
if zoom:
newViewPos = numpy.array([obj.getPosition()[0], obj.getPosition()[1], obj.getMaximum()[2] / 2])
- self._animView = anim(self._viewTarget.copy(), newViewPos, 0.5)
+ self._animView = openglGui.animation(self, self._viewTarget.copy(), newViewPos, 0.5)
newZoom = obj.getBoundaryCircle() * 6
if newZoom > numpy.max(self._machineSize) * 3:
newZoom = numpy.max(self._machineSize) * 3
- self._animZoom = anim(self._zoom, newZoom, 0.5)
+ self._animZoom = openglGui.animation(self, self._zoom, newZoom, 0.5)
def updateProfileToControls(self):
oldSimpleMode = self._isSimpleMode
self._objectLoadShader.release()
self._objectLoadShader = s
for obj in self._scene.objects():
- obj._loadAnim = anim(1, 0, 1.5)
+ obj._loadAnim = openglGui.animation(self, 1, 0, 1.5)
self.Refresh()
def OnMouseDown(self,e):
glEnd()
glPopMatrix()
+def glDrawStretchedQuad(x, y, w, h, cornerSize, texID):
+ tx0 = float(texID % 4) / 4
+ ty0 = float(int(texID / 4)) / 8
+ tx1 = tx0 + 0.25 / 2.0
+ ty1 = ty0 + 0.125 / 2.0
+ tx2 = tx0 + 0.25
+ ty2 = ty0 + 0.125
+
+ glPushMatrix()
+ glTranslatef(x, y, 0)
+ glEnable(GL_TEXTURE_2D)
+ glBegin(GL_QUADS)
+ #TopLeft
+ glTexCoord2f(tx1, ty0)
+ glVertex2f( cornerSize, 0)
+ glTexCoord2f(tx0, ty0)
+ glVertex2f( 0, 0)
+ glTexCoord2f(tx0, ty1)
+ glVertex2f( 0, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, cornerSize)
+ #TopRight
+ glTexCoord2f(tx2, ty0)
+ glVertex2f( w, 0)
+ glTexCoord2f(tx1, ty0)
+ glVertex2f( w - cornerSize, 0)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w - cornerSize, cornerSize)
+ glTexCoord2f(tx2, ty1)
+ glVertex2f( w, cornerSize)
+ #BottomLeft
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, h - cornerSize)
+ glTexCoord2f(tx0, ty1)
+ glVertex2f( 0, h - cornerSize)
+ glTexCoord2f(tx0, ty2)
+ glVertex2f( 0, h)
+ glTexCoord2f(tx1, ty2)
+ glVertex2f( cornerSize, h)
+ #BottomRight
+ glTexCoord2f(tx2, ty1)
+ glVertex2f( w, h - cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w - cornerSize, h - cornerSize)
+ glTexCoord2f(tx1, ty2)
+ glVertex2f( w - cornerSize, h)
+ glTexCoord2f(tx2, ty2)
+ glVertex2f( w, h)
+
+ #Center
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, h-cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, h-cornerSize)
+
+ #Right
+ glTexCoord2f(tx2, ty1)
+ glVertex2f( w, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, h-cornerSize)
+ glTexCoord2f(tx2, ty1)
+ glVertex2f( w, h-cornerSize)
+
+ #Left
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, cornerSize)
+ glTexCoord2f(tx0, ty1)
+ glVertex2f( 0, cornerSize)
+ glTexCoord2f(tx0, ty1)
+ glVertex2f( 0, h-cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, h-cornerSize)
+
+ #Top
+ glTexCoord2f(tx1, ty0)
+ glVertex2f( w-cornerSize, 0)
+ glTexCoord2f(tx1, ty0)
+ glVertex2f( cornerSize, 0)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, cornerSize)
+
+ #Bottom
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( w-cornerSize, h-cornerSize)
+ glTexCoord2f(tx1, ty1)
+ glVertex2f( cornerSize, h-cornerSize)
+ glTexCoord2f(tx1, ty2)
+ glVertex2f( cornerSize, h)
+ glTexCoord2f(tx1, ty2)
+ glVertex2f( w-cornerSize, h)
+
+ glEnd()
+ glDisable(GL_TEXTURE_2D)
+ glPopMatrix()
+
def unproject(winx, winy, winz, modelMatrix, projMatrix, viewport):
npModelMatrix = numpy.matrix(numpy.array(modelMatrix, numpy.float64).reshape((4,4)))
npProjMatrix = numpy.matrix(numpy.array(projMatrix, numpy.float64).reshape((4,4)))
import traceback
import sys
import os
+import time
from wx import glcanvas
import OpenGL
from Cura.gui.util import opengl
+class animation(object):
+ def __init__(self, gui, start, end, runTime):
+ self._start = start
+ self._end = end
+ self._startTime = time.time()
+ self._runTime = runTime
+ gui._animationList.append(self)
+
+ def isDone(self):
+ return time.time() > self._startTime + self._runTime
+
+ def getPosition(self):
+ if self.isDone():
+ return self._end
+ f = (time.time() - self._startTime) / self._runTime
+ ts = f*f
+ tc = f*f*f
+ #f = 6*tc*ts + -15*ts*ts + 10*tc
+ f = tc + -3*ts + 3*f
+ return self._start + (self._end - self._start) * f
+
class glGuiControl(object):
def __init__(self, parent, pos):
self._parent = parent
self._glRobotTexture = None
self._buttonSize = 64
+ self._animationList = []
self.glReleaseList = []
wx.EVT_PAINT(self, self._OnGuiPaint)
wx.EVT_MOTION(self, self._OnGuiMouseMotion)
wx.EVT_CHAR(self, self._OnGuiKeyChar)
wx.EVT_KILL_FOCUS(self, self.OnFocusLost)
+ wx.EVT_IDLE(self, self._OnIdle)
+
+ def _OnIdle(self, e):
+ if len(self._animationList) > 0:
+ for anim in self._animationList:
+ if anim.isDone():
+ self._animationList.remove(anim)
+ self.Refresh()
def _OnGuiKeyChar(self, e):
if self._focus is not None:
bs = self._parent._buttonSize
pos = self._getPixelPos()
- glPushMatrix()
- glTranslatef(pos[0], pos[1], 0)
- glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
- glEnable(GL_TEXTURE_2D)
-
size = self._layout.getLayoutSize()
glColor4ub(255,255,255,255)
- glBegin(GL_QUADS)
- bs /= 2
- tc = 1 / 4 / 2
-
-# glTexCoord2f(1, 0)
-# glVertex2f( size[0], 0)
-# glTexCoord2f(0, 0)
-# glVertex2f( 0, 0)
-# glTexCoord2f(0, 1)
-# glVertex2f( 0, size[1])
-# glTexCoord2f(1, 1)
-# glVertex2f( size[0], size[1])
- #TopLeft
- glTexCoord2f(tc, 0)
- glVertex2f( bs, 0)
- glTexCoord2f(0, 0)
- glVertex2f( 0, 0)
- glTexCoord2f(0, tc/2)
- glVertex2f( 0, bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, bs)
- #TopRight
- glTexCoord2f(tc+tc, 0)
- glVertex2f( size[0], 0)
- glTexCoord2f(tc, 0)
- glVertex2f( size[0] - bs, 0)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0] - bs, bs)
- glTexCoord2f(tc+tc, tc/2)
- glVertex2f( size[0], bs)
- #BottomLeft
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, size[1] - bs)
- glTexCoord2f(0, tc/2)
- glVertex2f( 0, size[1] - bs)
- glTexCoord2f(0, tc/2+tc/2)
- glVertex2f( 0, size[1])
- glTexCoord2f(tc, tc/2+tc/2)
- glVertex2f( bs, size[1])
- #BottomRight
- glTexCoord2f(tc+tc, tc/2)
- glVertex2f( size[0], size[1] - bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0] - bs, size[1] - bs)
- glTexCoord2f(tc, tc/2+tc/2)
- glVertex2f( size[0] - bs, size[1])
- glTexCoord2f(tc+tc, tc/2+tc/2)
- glVertex2f( size[0], size[1])
-
- #Center
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, size[1]-bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, size[1]-bs)
-
- #Right
- glTexCoord2f(tc+tc, tc/2)
- glVertex2f( size[0], bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, size[1]-bs)
- glTexCoord2f(tc+tc, tc/2)
- glVertex2f( size[0], size[1]-bs)
-
- #Left
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, bs)
- glTexCoord2f(0, tc/2)
- glVertex2f( 0, bs)
- glTexCoord2f(0, tc/2)
- glVertex2f( 0, size[1]-bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, size[1]-bs)
-
- #Top
- glTexCoord2f(tc, 0)
- glVertex2f( size[0]-bs, 0)
- glTexCoord2f(tc, 0)
- glVertex2f( bs, 0)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, bs)
-
- #Bottom
- glTexCoord2f(tc, tc/2)
- glVertex2f( size[0]-bs, size[1]-bs)
- glTexCoord2f(tc, tc/2)
- glVertex2f( bs, size[1]-bs)
- glTexCoord2f(tc, tc/2+tc/2)
- glVertex2f( bs, size[1])
- glTexCoord2f(tc, tc/2+tc/2)
- glVertex2f( size[0]-bs, size[1])
-
- glEnd()
- glDisable(GL_TEXTURE_2D)
- glPopMatrix()
+ opengl.glDrawStretchedQuad(pos[0], pos[1], size[0], size[1], bs/2, 0)
#Draw the controls on the frame
super(glFrame, self).draw()