self.checkReloadFileTimer.Start(1000)
group = []
- self.rotateToolButton = openglGui.glRadioButton(self.glCanvas, 1, 'Rotate', (0,-1), group, self.OnToolSelect)
- self.scaleToolButton = openglGui.glRadioButton(self.glCanvas, 2, 'Scale', (1,-1), group, self.OnToolSelect)
- self.mirrorToolButton = openglGui.glRadioButton(self.glCanvas, 12, 'Mirror', (2,-1), group, self.OnToolSelect)
+ self.rotateToolButton = openglGui.glRadioButton(self.glCanvas, 8, 'Rotate', (0,-1), group, self.OnToolSelect)
+ self.scaleToolButton = openglGui.glRadioButton(self.glCanvas, 9, 'Scale', (1,-1), group, self.OnToolSelect)
+ self.mirrorToolButton = openglGui.glRadioButton(self.glCanvas, 10, 'Mirror', (2,-1), group, self.OnToolSelect)
- self.resetRotationButton = openglGui.glButton(self.glCanvas, 4, 'Reset rotation', (0,-2), self.OnRotateReset)
- self.layFlatButton = openglGui.glButton(self.glCanvas, 5, 'Lay flat', (0,-3), self.OnLayFlat)
+ self.resetRotationButton = openglGui.glButton(self.glCanvas, 12, 'Reset rotation', (0,-2), self.OnRotateReset)
+ self.layFlatButton = openglGui.glButton(self.glCanvas, 16, 'Lay flat', (0,-3), self.OnLayFlat)
- self.resetScaleButton = openglGui.glButton(self.glCanvas, 8, 'Scale reset', (1,-2), self.OnScaleReset)
- self.scaleMaxButton = openglGui.glButton(self.glCanvas, 9, 'Scale to machine size', (1,-3), self.OnScaleMax)
+ self.resetScaleButton = openglGui.glButton(self.glCanvas, 13, 'Scale reset', (1,-2), self.OnScaleReset)
+ self.scaleMaxButton = openglGui.glButton(self.glCanvas, 17, 'Scale to machine size', (1,-3), self.OnScaleMax)
- self.mirrorXButton = openglGui.glButton(self.glCanvas, 12, 'Mirror X', (2,-2), lambda : self.OnMirror(0))
- self.mirrorYButton = openglGui.glButton(self.glCanvas, 13, 'Mirror Y', (2,-3), lambda : self.OnMirror(1))
- self.mirrorZButton = openglGui.glButton(self.glCanvas, 14, 'Mirror Z', (2,-4), lambda : self.OnMirror(2))
+ self.mirrorXButton = openglGui.glButton(self.glCanvas, 14, 'Mirror X', (2,-2), lambda : self.OnMirror(0))
+ self.mirrorYButton = openglGui.glButton(self.glCanvas, 18, 'Mirror Y', (2,-3), lambda : self.OnMirror(1))
+ self.mirrorZButton = openglGui.glButton(self.glCanvas, 22, 'Mirror Z', (2,-4), lambda : self.OnMirror(2))
- self.openFileButton = openglGui.glButton(self.glCanvas, 3, 'Load model', (0,0), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(1))
- self.sliceButton = openglGui.glButton(self.glCanvas, 6, 'Prepare model', (1,0), lambda : self.GetParent().GetParent().GetParent().OnSlice(None))
- self.printButton = openglGui.glButton(self.glCanvas, 7, 'Print model', (2,0), lambda : self.GetParent().GetParent().GetParent().OnPrint(None))
+ self.openFileButton = openglGui.glButton(self.glCanvas, 4, 'Load model', (0,0), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(1))
+ self.sliceButton = openglGui.glButton(self.glCanvas, 5, 'Prepare model', (1,0), lambda : self.GetParent().GetParent().GetParent().OnSlice(None))
+ self.printButton = openglGui.glButton(self.glCanvas, 6, 'Print model', (2,0), lambda : self.GetParent().GetParent().GetParent().OnPrint(None))
extruderCount = int(profile.getPreference('extruder_amount'))
if extruderCount > 1:
- openglGui.glButton(self.glCanvas, 3, 'Load dual model', (0,1), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(2))
+ openglGui.glButton(self.glCanvas, 4, 'Load dual model', (0,1), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(2))
if extruderCount > 2:
- openglGui.glButton(self.glCanvas, 3, 'Load triple model', (0,2), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(3))
+ openglGui.glButton(self.glCanvas, 4, 'Load triple model', (0,2), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(3))
if extruderCount > 3:
- openglGui.glButton(self.glCanvas, 3, 'Load quad model', (0,3), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(4))
+ openglGui.glButton(self.glCanvas, 4, 'Load quad model', (0,3), lambda : self.GetParent().GetParent().GetParent()._showModelLoadDialog(4))
- self.scaleForm = openglGui.glFrame(self.glCanvas, (2, -3))
+ self.scaleForm = openglGui.glFrame(self.glCanvas, (2, -2))
openglGui.glGuiLayoutGrid(self.scaleForm)
openglGui.glLabel(self.scaleForm, 'Scale X', (0,0))
self.scaleXctrl = openglGui.glNumberCtrl(self.scaleForm, '1.0', (1,0), lambda value: self.OnScaleEntry(value, 0))
openglGui.glLabel(self.scaleForm, 'Uniform scale', (0,8))
self.scaleUniform = openglGui.glCheckbox(self.scaleForm, True, (1,8), None)
- self.viewSelection = openglGui.glComboButton(self.glCanvas, 'View mode', [0,1,2,3,4], ['3D Model', 'Transparent', 'X-Ray', 'Overhang', 'Layers'], (-1,0), self.OnViewChange)
+ self.viewSelection = openglGui.glComboButton(self.glCanvas, 'View mode', [7,11,15,19,23], ['3D Model', 'Transparent', 'X-Ray', 'Overhang', 'Layers'], (-1,0), self.OnViewChange)
self.layerSelect = openglGui.glSlider(self.glCanvas, 0, 0, 100, (-1,-2), self.OnLayerNrChange)
self.OnViewChange()
self.OnToolSelect()
- self.returnToModelViewAndUpdateModel()
+ self.updateModelTransform()
self.matrix = numpy.matrix(numpy.array(profile.getObjectMatrix(), numpy.float64).reshape((3,3,)))
- def returnToModelViewAndUpdateModel(self):
- if self.glCanvas.viewMode == 'GCode' or self.glCanvas.viewMode == 'Mixed':
- self.setViewMode('Normal')
- self.updateModelTransform()
-
- def OnToolSelect(self, resetView = True):
+ def OnToolSelect(self):
if self.rotateToolButton.getSelected():
self.tool = previewTools.toolRotate(self.glCanvas)
elif self.scaleToolButton.getSelected():
self.mirrorXButton.setHidden(not self.mirrorToolButton.getSelected())
self.mirrorYButton.setHidden(not self.mirrorToolButton.getSelected())
self.mirrorZButton.setHidden(not self.mirrorToolButton.getSelected())
- if resetView:
- self.returnToModelViewAndUpdateModel()
+ self.updateModelTransform()
def OnScaleEntry(self, value, axis):
try:
self.rotateToolButton.setSelected(False)
self.scaleToolButton.setSelected(False)
self.mirrorToolButton.setSelected(False)
- self.OnToolSelect(False)
self.glCanvas.Refresh()
def updateModelTransform(self, f=0):
def drawModel(self, displayList):
vMin = self.parent.objectsMinV
vMax = self.parent.objectsMaxV
- offset = - vMin - (vMax - vMin) / 2
+ if vMin is None:
+ return
+ offset = - vMin - (vMax - vMin) / 2
matrix = opengl.convert3x3MatrixTo4x4(self.parent.matrix)
for c in s:
glutBitmapCharacter(OpenGL.GLUT.GLUT_BITMAP_HELVETICA_18, ord(c))
+def glDrawTexturedQuad(x, y, w, h, texID, mirror = 0):
+ tx = float(texID % 4) / 4
+ ty = float(int(texID / 4)) / 8
+ tsx = 0.25
+ tsy = 0.125
+ if mirror & 1:
+ tx += tsx
+ tsx = -tsx
+ if mirror & 2:
+ ty += tsy
+ tsy = -tsy
+ glPushMatrix()
+ glTranslatef(x, y, 0)
+ glEnable(GL_TEXTURE_2D)
+ glBegin(GL_QUADS)
+ glTexCoord2f(tx+tsx, ty)
+ glVertex2f(w, 0)
+ glTexCoord2f(tx, ty)
+ glVertex2f(0, 0)
+ glTexCoord2f(tx, ty+tsy)
+ glVertex2f(0, h)
+ glTexCoord2f(tx+tsx, ty+tsy)
+ glVertex2f(w, h)
+ glEnd()
+ 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)))
from __future__ import division
import wx
-import math
+import traceback
+import sys
+import os
from wx import glcanvas
import OpenGL
self._focus = None
self._container = None
self._container = glGuiContainer(self, (0,0))
+ self._shownError = False
self._context = glcanvas.GLContext(self)
self._glButtonsTexture = None
self._container.updateLayout()
dc = wx.PaintDC(self)
- self.SetCurrent(self._context)
- self.OnPaint(e)
- self._drawGui()
- glFlush()
- self.SwapBuffers()
+ try:
+ self.SetCurrent(self._context)
+ self.OnPaint(e)
+ self._drawGui()
+ glFlush()
+ self.SwapBuffers()
+ except:
+ errStr = 'An error has occurred during the 3D view drawing.'
+ tb = traceback.extract_tb(sys.exc_info()[2])
+ errStr += "\n%s: '%s'" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]))
+ for n in xrange(len(tb)-1, -1, -1):
+ locationInfo = tb[n]
+ errStr += "\n @ %s:%s:%d" % (os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1])
+ if not self._shownError:
+ wx.CallAfter(wx.MessageBox, errStr, '3D window error', wx.OK | wx.ICON_EXCLAMATION)
+ self._shownError = True
def _drawGui(self):
if self._glButtonsTexture is None:
self._parent = parent
self._parent._layout = self
self._size = 0,0
+ self._alignBottom = True
def update(self):
borderSize = self._parent._base._buttonSize * 0.2
heights[y] = h
else:
heights[y] = max(heights[y], h)
+ self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
+ if self._alignBottom:
+ y0 -= self._size[1] - self._parent.getSize()[3]
+ self._parent.setSize(x0 - borderSize, y0 - borderSize, self._size[0], self._size[1])
for ctrl in self._parent._glGuiControlList:
x, y = ctrl._pos
x1 = x0
heights[n] = 3
y1 += heights[n]
ctrl.setSize(x1, y1, widths[x], heights[y])
- self._size = sum(widths.values()) + borderSize * 2, sum(heights.values()) + borderSize * 2
def getLayoutSize(self):
return self._size
bs = self._base._buttonSize
pos = self._getPixelPos()
- glPushMatrix()
- glTranslatef(pos[0], pos[1], 0)
glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
- glEnable(GL_TEXTURE_2D)
scale = 0.8
if self._selected:
scale = 1.0
elif self._focus:
scale = 0.9
- glScalef(bs * scale, bs * scale, bs * scale)
if self._disabled:
glColor4ub(128,128,128,128)
else:
glColor4ub(255,255,255,255)
- glBegin(GL_QUADS)
- glTexCoord2f(cx+0.25, cy)
- glVertex2f( 0.5,-0.5)
- glTexCoord2f(cx, cy)
- glVertex2f(-0.5,-0.5)
- glTexCoord2f(cx, cy+0.25)
- glVertex2f(-0.5, 0.5)
- glTexCoord2f(cx+0.25, cy+0.25)
- glVertex2f( 0.5, 0.5)
- glEnd()
+ opengl.glDrawTexturedQuad(pos[0]-bs*scale/2, pos[1]-bs*scale/2, bs*scale, bs*scale, self._imageID)
+ glPushMatrix()
+ glTranslatef(pos[0], pos[1], 0)
glDisable(GL_TEXTURE_2D)
if self._focus:
glColor4ub(0,0,0,255)
- glTranslatef(0, -0.55, 0)
+ glTranslatef(0, -0.55*bs, 0)
opengl.glDrawStringCenter(self._tooltip)
glPopMatrix()
self._selection = 0
def _onComboOpenSelect(self):
- self._base._focus = self
+ if self.hasFocus():
+ self._base._focus = None
+ else:
+ self._base._focus = self
def draw(self):
if self._hidden:
return
self._selected = self.hasFocus()
super(glComboButton, self).draw()
- if not self._selected:
- return
bs = self._base._buttonSize / 2
pos = self._getPixelPos()
+ if not self._selected:
+ return
+
glPushMatrix()
glTranslatef(pos[0]+bs*0.5, pos[1] + bs*0.5, 0)
glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
glScalef(bs, bs, bs)
for n in xrange(0, len(self._imageIDs)):
- cx = (self._imageIDs[n] % 4) / 4
- cy = int(self._imageIDs[n] / 4) / 4
- glEnable(GL_TEXTURE_2D)
glTranslatef(0, 1, 0)
- if self._disabled:
- glColor4ub(128,128,128,128)
- else:
- glColor4ub(255,255,255,255)
- glBegin(GL_QUADS)
- glTexCoord2f(cx+0.25, cy)
- glVertex2f( 0.5,-0.5)
- glTexCoord2f(cx, cy)
- glVertex2f(-0.5,-0.5)
- glTexCoord2f(cx, cy+0.25)
- glVertex2f(-0.5, 0.5)
- glTexCoord2f(cx+0.25, cy+0.25)
- glVertex2f( 0.5, 0.5)
- glEnd()
+ glColor3ub(255,255,255)
+ opengl.glDrawTexturedQuad(-0.5,-0.5,1,1, self._imageIDs[n])
glDisable(GL_TEXTURE_2D)
glPushMatrix()
glPushMatrix()
glTranslatef(pos[0], pos[1], 0)
- glDisable(GL_TEXTURE_2D)
+ glBindTexture(GL_TEXTURE_2D, self._base._glButtonsTexture)
+ glEnable(GL_TEXTURE_2D)
size = self._layout.getLayoutSize()
- glColor4ub(60,60,60,255)
+ glColor4ub(255,255,255,255)
glBegin(GL_QUADS)
- glTexCoord2f(1, 0)
- glVertex2f( size[0], 0)
+ 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, 1)
+ 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(1, 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()
glPushMatrix()
glTranslatef(x, y, 0)
- glColor4ub(255,255,255,128)
- glBegin(GL_QUADS)
- glTexCoord2f(1, 0)
- glVertex2f( w, 0)
- glTexCoord2f(0, 0)
- glVertex2f( 0, 0)
- glTexCoord2f(0, 1)
- glVertex2f( 0, h)
- glTexCoord2f(1, 1)
- glVertex2f( w, h)
- glEnd()
+# glColor4ub(255,255,255,128)
+# glBegin(GL_QUADS)
+# glTexCoord2f(1, 0)
+# glVertex2f( w, 0)
+# glTexCoord2f(0, 0)
+# glVertex2f( 0, 0)
+# glTexCoord2f(0, 1)
+# glVertex2f( 0, h)
+# glTexCoord2f(1, 1)
+# glVertex2f( w, h)
+# glEnd()
glTranslate(5, h - 5, 0)
- glColor4ub(0,0,0,255)
+ glColor4ub(255,255,255,255)
opengl.glDrawStringLeft(self._label)
glPopMatrix()
glTexCoord2f(0, 0)
glVertex2f( 0, 0)
glTexCoord2f(0, 1)
- glVertex2f( 0, h)
+ glVertex2f( 0, h-1)
glTexCoord2f(1, 1)
- glVertex2f( w, h)
+ glVertex2f( w, h-1)
glEnd()
glTranslate(5, h - 5, 0)
glPushMatrix()
glTranslatef(x, y, 0)
+ glColor3ub(255,255,255)
if self._value:
- glColor4ub(0,255,0,255)
+ opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 28)
else:
- glColor4ub(255,0,0,255)
- glBegin(GL_QUADS)
- glTexCoord2f(1, 0)
- glVertex2f( w, 0)
- glTexCoord2f(0, 0)
- glVertex2f( 0, 0)
- glTexCoord2f(0, 1)
- glVertex2f( 0, h)
- glTexCoord2f(1, 1)
- glVertex2f( w, h)
- glEnd()
+ opengl.glDrawTexturedQuad(w/2-h/2,0, h, h, 29)
glPopMatrix()
zString = zString[0:zString.find(' ')]
clearZ = max(clearZ, float(zString) + 10)
profile.setTempOverride('clear_z', clearZ)
+ print position
+ print profile.getAlterationFileContents('nextobject.gcode')
resultFile.write(profile.getAlterationFileContents('nextobject.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))
output = []
pass
elif M == 113: #Extruder PWM (these should not be in the final GCode, but they are)
pass
+ elif M == 117: #LCD message
+ pass
elif M == 140: #Set bed temperature
pass
elif M == 190: #Set bed temperature & wait
if code not in self.regMatch:
self.regMatch[code] = re.compile(code + '([^\s]+)')
m = self.regMatch[code].search(line)
- if m == None:
+ if m is None:
return None
try:
return float(m.group(1))