import traceback
import threading
import math
+import platform
import OpenGL
OpenGL.ERROR_CHECKING = False
from OpenGL.GL import *
from Cura.gui import printWindow
+from Cura.gui import printWindow2
from Cura.util import profile
from Cura.util import meshLoader
from Cura.util import objectScene
from Cura.util import machineCom
from Cura.util import removableStorage
from Cura.util import gcodeInterpreter
+from Cura.util import explorer
+from Cura.util.printerConnection import printerConnectionManager
from Cura.gui.util import previewTools
from Cura.gui.util import opengl
from Cura.gui.util import openglGui
from Cura.gui.tools import youmagineGui
+from Cura.gui.tools import imageToMesh
class SceneView(openglGui.glGuiPanel):
def __init__(self, parent):
self._animView = None
self._animZoom = None
self._platformMesh = {}
+ self._platformTexture = None
self._isSimpleMode = True
self._usbPrintMonitor = printWindow.printProcessMonitor(lambda : self._queueRefresh())
+ self._printerConnectionManager = printerConnectionManager.PrinterConnectionManager()
self._viewport = None
self._modelMatrix = None
def loadSceneFiles(self, filenames):
self.youMagineButton.setDisabled(False)
- if self.viewSelection.getValue() == 4:
- self.viewSelection.setValue(0)
- self.OnViewChange()
+ #if self.viewSelection.getValue() == 4:
+ # self.viewSelection.setValue(0)
+ # self.OnViewChange()
self.loadScene(filenames)
def loadFiles(self, filenames):
+ mainWindow = self.GetParent().GetParent().GetParent()
+ # only one GCODE file can be active
+ # so if single gcode file, process this
+ # otherwise ignore all gcode files
gcodeFilename = None
- for filename in filenames:
- self.GetParent().GetParent().GetParent().addToModelMRU(filename)
- ext = filename[filename.rfind('.')+1:].upper()
- if ext == 'G' or ext == 'GCODE':
+ if len(filenames) == 1:
+ filename = filenames[0]
+ ext = os.path.splitext(filename)[1].lower()
+ if ext == '.g' or ext == '.gcode':
gcodeFilename = filename
+ mainWindow.addToModelMRU(filename)
if gcodeFilename is not None:
self.loadGCodeFile(gcodeFilename)
else:
- self.loadSceneFiles(filenames)
+ # process directories and special file types
+ # and keep scene files for later processing
+ scene_filenames = []
+ ignored_types = dict()
+ # use file list as queue
+ # pop first entry for processing and append new files at end
+ while filenames:
+ filename = filenames.pop(0)
+ if os.path.isdir(filename):
+ # directory: queue all included files and directories
+ filenames.extend(os.path.join(filename, f) for f in os.listdir(filename))
+ else:
+ ext = os.path.splitext(filename)[1].lower()
+ if ext == '.ini':
+ profile.loadProfile(filename)
+ mainWindow.addToProfileMRU(filename)
+ elif ext in meshLoader.loadSupportedExtensions() or ext in imageToMesh.supportedExtensions():
+ scene_filenames.append(filename)
+ mainWindow.addToModelMRU(filename)
+ else:
+ ignored_types[ext] = 1
+ if ignored_types:
+ ignored_types = ignored_types.keys()
+ ignored_types.sort()
+ self.notification.message("ignored: " + " ".join("*" + type for type in ignored_types))
+ mainWindow.updateProfileToAllControls()
+ # now process all the scene files
+ if scene_filenames:
+ self.loadSceneFiles(scene_filenames)
+ self._selectObject(None)
+ self.sceneUpdated()
+ newZoom = numpy.max(self._machineSize)
+ self._animView = openglGui.animation(self, self._viewTarget.copy(), numpy.array([0,0,0], numpy.float32), 0.5)
+ self._animZoom = openglGui.animation(self, self._zoom, newZoom, 0.5)
def showLoadModel(self, button = 1):
if button == 1:
dlg=wx.FileDialog(self, _("Open 3D model"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST|wx.FD_MULTIPLE)
- dlg.SetWildcard(meshLoader.loadWildcardFilter() + "|GCode file (*.gcode)|*.g;*.gcode;*.G;*.GCODE")
+ dlg.SetWildcard(meshLoader.loadWildcardFilter() + imageToMesh.wildcardList() + "|GCode file (*.gcode)|*.g;*.gcode;*.G;*.GCODE")
if dlg.ShowModal() != wx.ID_OK:
dlg.Destroy()
return
def OnPrintButton(self, button):
if button == 1:
+ connectionGroup = self._printerConnectionManager.getAvailableGroup()
if machineCom.machineIsConnected():
self.showPrintWindow()
- elif len(removableStorage.getPossibleSDcardDrives()) > 0:
+ elif len(removableStorage.getPossibleSDcardDrives()) > 0 and (connectionGroup is None or connectionGroup.getPriority() < 0):
drives = removableStorage.getPossibleSDcardDrives()
if len(drives) > 1:
dlg = wx.SingleChoiceDialog(self, "Select SD drive", "Multiple removable drives have been found,\nplease select your SD card drive", map(lambda n: n[0], drives))
drive = drives[0]
filename = self._scene._objectList[0].getName() + '.gcode'
threading.Thread(target=self._copyFile,args=(self._gcodeFilename, drive[1] + filename, drive[1])).start()
+ elif connectionGroup is not None:
+ connections = connectionGroup.getAvailableConnections()
+ if len(connections) < 2:
+ connection = connections[0]
+ else:
+ dlg = wx.SingleChoiceDialog(self, "Select the %s connection to use" % (connectionGroup.getName()), "Multiple %s connections found" % (connectionGroup.getName()), map(lambda n: n.getName(), connections))
+ if dlg.ShowModal() != wx.ID_OK:
+ dlg.Destroy()
+ return
+ connection = connections[dlg.GetSelection()]
+ dlg.Destroy()
+ self._openPrintWindowForConnection(connection)
else:
self.showSaveGCode()
if button == 3:
menu = wx.Menu()
self.Bind(wx.EVT_MENU, lambda e: self.showPrintWindow(), menu.Append(-1, _("Print with USB")))
+ connections = self._printerConnectionManager.getAvailableConnections()
+ menu.connectionMap = {}
+ for connection in connections:
+ i = menu.Append(-1, _("Print with %s") % (connection.getName()))
+ menu.connectionMap[i.GetId()] = connection
+ self.Bind(wx.EVT_MENU, lambda e: self._openPrintWindowForConnection(e.GetEventObject().connectionMap[e.GetId()]), i)
self.Bind(wx.EVT_MENU, lambda e: self.showSaveGCode(), menu.Append(-1, _("Save GCode...")))
self.Bind(wx.EVT_MENU, lambda e: self._showSliceLog(), menu.Append(-1, _("Slice engine log...")))
self.PopupMenu(menu)
menu.Destroy()
+ def _openPrintWindowForConnection(self, connection):
+ print '_openPrintWindowForConnection', connection.getName()
+ if connection.window is None or not connection.window:
+ connection.window = printWindow2.printWindow(connection)
+ connection.window.Show()
+ connection.window.Raise()
+ if not connection.loadFile(self._gcodeFilename):
+ if connection.isPrinting():
+ self.notification.message("Cannot start print, because other print still running.")
+ else:
+ self.notification.message("Failed to start print...")
+
def showPrintWindow(self):
if self._gcodeFilename is None:
return
+ if profile.getMachineSetting('gcode_flavor') == 'UltiGCode':
+ wx.MessageBox(_("USB printing on the Ultimaker2 is not supported."), _("USB Printing Error"), wx.OK | wx.ICON_WARNING)
+ return
self._usbPrintMonitor.loadFile(self._gcodeFilename, self._slicer.getID())
if self._gcodeFilename == self._slicer.getGCodeFilename():
self._slicer.submitSliceInfoOnline()
def showSaveGCode(self):
- defPath = profile.getPreference('lastFile')
- defPath = defPath[0:defPath.rfind('.')] + '.gcode'
- dlg=wx.FileDialog(self, _("Save toolpath"), defPath, style=wx.FD_SAVE)
- dlg.SetFilename(self._scene._objectList[0].getName())
+ if len(self._scene._objectList) < 1:
+ return
+ dlg=wx.FileDialog(self, _("Save toolpath"), os.path.dirname(profile.getPreference('lastFile')), style=wx.FD_SAVE)
+ filename = self._scene._objectList[0].getName() + '.gcode'
+ dlg.SetFilename(filename)
dlg.SetWildcard('Toolpath (*.gcode)|*.gcode;*.g')
if dlg.ShowModal() != wx.ID_OK:
dlg.Destroy()
self.notification.message("Failed to save")
else:
if allowEject:
- self.notification.message("Saved as %s" % (fileB), lambda : self.notification.message('You can now eject the card.') if removableStorage.ejectDrive(allowEject) else self.notification.message('Safe remove failed...'))
+ self.notification.message("Saved as %s" % (fileB), lambda : self._doEjectSD(allowEject), 31, 'Eject')
+ elif explorer.hasExplorer():
+ self.notification.message("Saved as %s" % (fileB), lambda : explorer.openExplorer(fileB), 4, 'Open folder')
else:
self.notification.message("Saved as %s" % (fileB))
self.printButton.setProgressBar(None)
if fileA == self._slicer.getGCodeFilename():
self._slicer.submitSliceInfoOnline()
+ def _doEjectSD(self, drive):
+ if removableStorage.ejectDrive(drive):
+ self.notification.message('You can now eject the card.')
+ else:
+ self.notification.message('Safe remove failed...')
+
def _showSliceLog(self):
dlg = wx.TextEntryDialog(self, _("The slicing engine reported the following"), _("Engine log..."), '\n'.join(self._slicer.getSliceLog()), wx.TE_MULTILINE | wx.OK | wx.CENTRE)
dlg.ShowModal()
if self._selectedObj is None:
return
self._selectedObj.resetRotation()
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.sceneUpdated()
if self._selectedObj is None:
return
self._selectedObj.layFlat()
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.sceneUpdated()
def OnScaleMax(self, button):
if self._selectedObj is None:
return
- self._selectedObj.scaleUpTo(self._machineSize - numpy.array(profile.calculateObjectSizeOffsets() + [0.0], numpy.float32) * 2 - numpy.array([1,1,1], numpy.float32))
- self._scene.pushFree()
+ machine = profile.getMachineSetting('machine_type')
+ self._selectedObj.setPosition(numpy.array([0.0, 0.0]))
+ self._scene.pushFree(self._selectedObj)
+ #self.sceneUpdated()
+ if machine == "ultimaker2":
+ #This is bad and Jaime should feel bad!
+ self._selectedObj.setPosition(numpy.array([0.0,-10.0]))
+ self._selectedObj.scaleUpTo(self._machineSize - numpy.array(profile.calculateObjectSizeOffsets() + [0.0], numpy.float32) * 2 - numpy.array([1,1,1], numpy.float32))
+ self._selectedObj.setPosition(numpy.array([0.0,0.0]))
+ self._scene.pushFree(self._selectedObj)
+ else:
+ self._selectedObj.setPosition(numpy.array([0.0, 0.0]))
+ self._scene.pushFree(self._selectedObj)
+ self._selectedObj.scaleUpTo(self._machineSize - numpy.array(profile.calculateObjectSizeOffsets() + [0.0], numpy.float32) * 2 - numpy.array([1,1,1], numpy.float32))
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.updateProfileToControls()
self.sceneUpdated()
return
self._selectedObj.setScale(value, axis, self.scaleUniform.getValue())
self.updateProfileToControls()
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.sceneUpdated()
return
self._selectedObj.setSize(value, axis, self.scaleUniform.getValue())
self.updateProfileToControls()
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.sceneUpdated()
if self._focusObj is None:
return
obj = self._focusObj
- dlg = wx.NumberEntryDialog(self, "How many copies do you want?", "Copies", "Multiply", 1, 1, 100)
+ dlg = wx.NumberEntryDialog(self, _("How many copies do you want?"), _("Number of copies"), _("Multiply"), 1, 1, 100)
if dlg.ShowModal() != wx.ID_OK:
dlg.Destroy()
return
self._selectObject(None)
self.sceneUpdated()
+ def OnCenter(self, e):
+ if self._focusObj is None:
+ return
+ self._focusObj.setPosition(numpy.array([0.0, 0.0]))
+ self._scene.pushFree(self._selectedObj)
+ newViewPos = numpy.array([self._focusObj.getPosition()[0], self._focusObj.getPosition()[1], self._focusObj.getSize()[2] / 2])
+ self._animView = openglGui.animation(self, self._viewTarget.copy(), newViewPos, 0.5)
+ self.sceneUpdated()
+
def _splitCallback(self, progress):
print progress
def sceneUpdated(self):
self._sceneUpdateTimer.Start(500, True)
self._slicer.abortSlicer()
- self._scene.setSizeOffsets(numpy.array(profile.calculateObjectSizeOffsets(), numpy.float32))
+ self._scene.updateSizeOffsets()
self.QueueRefresh()
def _onRunSlicer(self, e):
self._gcodeVBOs = []
if ready:
self.printButton.setProgressBar(None)
- cost = self._slicer.getFilamentCost()
- if cost is not None:
- self.printButton.setBottomText('%s\n%s\n%s' % (self._slicer.getPrintTime(), self._slicer.getFilamentAmount(), cost))
- else:
- self.printButton.setBottomText('%s\n%s' % (self._slicer.getPrintTime(), self._slicer.getFilamentAmount()))
+ text = '%s' % (self._slicer.getPrintTime())
+ for e in xrange(0, int(profile.getMachineSetting('extruder_amount'))):
+ amount = self._slicer.getFilamentAmount(e)
+ if amount is None:
+ continue
+ text += '\n%s' % (amount)
+ cost = self._slicer.getFilamentCost(e)
+ if cost is not None:
+ text += '\n%s' % (cost)
+ self.printButton.setBottomText(text)
self._gcode = gcodeInterpreter.gcode()
self._gcodeFilename = self._slicer.getGCodeFilename()
else:
self._gcode.load(self._gcodeFilename)
def _gcodeLoadCallback(self, progress):
- if self._gcode is None:
+ if not self or self._gcode is None:
return True
if len(self._gcode.layerList) % 15 == 0:
time.sleep(0.1)
def loadScene(self, fileList):
for filename in fileList:
try:
- objList = meshLoader.loadMeshes(filename)
+ ext = os.path.splitext(filename)[1].lower()
+ if ext in imageToMesh.supportedExtensions():
+ imageToMesh.convertImageDialog(self, filename).Show()
+ objList = []
+ else:
+ objList = meshLoader.loadMeshes(filename)
except:
traceback.print_exc()
else:
else:
obj._loadAnim = None
self._scene.add(obj)
- self._scene.centerAll()
+ if not self._scene.checkPlatform(obj):
+ self._scene.centerAll()
self._selectObject(obj)
if obj.getScale()[0] < 1.0:
self.notification.message("Warning: Object scaled down.")
def _selectObject(self, obj, zoom = True):
if obj != self._selectedObj:
self._selectedObj = obj
- self.updateProfileToControls()
+ self.updateModelSettingsToControls()
self.updateToolButtons()
if zoom and obj is not None:
- newViewPos = numpy.array([obj.getPosition()[0], obj.getPosition()[1], obj.getMaximum()[2] / 2])
+ newViewPos = numpy.array([obj.getPosition()[0], obj.getPosition()[1], obj.getSize()[2] / 2])
self._animView = openglGui.animation(self, self._viewTarget.copy(), newViewPos, 0.5)
newZoom = obj.getBoundaryCircle() * 6
if newZoom > numpy.max(self._machineSize) * 3:
if self._isSimpleMode != oldSimpleMode:
self._scene.arrangeAll()
self.sceneUpdated()
+ self._scene.updateSizeOffsets(True)
self._machineSize = numpy.array([profile.getMachineSettingFloat('machine_width'), profile.getMachineSettingFloat('machine_depth'), profile.getMachineSettingFloat('machine_height')])
self._objColors[0] = profile.getPreferenceColour('model_colour')
self._objColors[1] = profile.getPreferenceColour('model_colour2')
self._objColors[2] = profile.getPreferenceColour('model_colour3')
self._objColors[3] = profile.getPreferenceColour('model_colour4')
- self._scene.setMachineSize(self._machineSize)
- self._scene.setSizeOffsets(numpy.array(profile.calculateObjectSizeOffsets(), numpy.float32))
- self._scene.setHeadSize(profile.getMachineSettingFloat('extruder_head_size_min_x'), profile.getMachineSettingFloat('extruder_head_size_max_x'), profile.getMachineSettingFloat('extruder_head_size_min_y'), profile.getMachineSettingFloat('extruder_head_size_max_y'), profile.getMachineSettingFloat('extruder_head_size_height'))
+ self._scene.updateMachineDimensions()
+ self.updateModelSettingsToControls()
+ def updateModelSettingsToControls(self):
if self._selectedObj is not None:
scale = self._selectedObj.getScale()
size = self._selectedObj.getSize()
self.scaleZmmctrl.setValue(round(size[2], 2))
def OnKeyChar(self, keyCode):
- if keyCode == wx.WXK_DELETE or keyCode == wx.WXK_NUMPAD_DELETE:
+ if keyCode == wx.WXK_DELETE or keyCode == wx.WXK_NUMPAD_DELETE or (keyCode == wx.WXK_BACK and platform.system() == "Darwin"):
if self._selectedObj is not None:
self._deleteObject(self._selectedObj)
self.QueueRefresh()
- if keyCode == wx.WXK_UP:
- self.layerSelect.setValue(self.layerSelect.getValue() + 1)
- self.QueueRefresh()
- elif keyCode == wx.WXK_DOWN:
- self.layerSelect.setValue(self.layerSelect.getValue() - 1)
- self.QueueRefresh()
- elif keyCode == wx.WXK_PAGEUP:
- self.layerSelect.setValue(self.layerSelect.getValue() + 10)
- self.QueueRefresh()
- elif keyCode == wx.WXK_PAGEDOWN:
- self.layerSelect.setValue(self.layerSelect.getValue() - 10)
- self.QueueRefresh()
+ if self.viewMode == 'gcode':
+ if keyCode == wx.WXK_UP:
+ self.layerSelect.setValue(self.layerSelect.getValue() + 1)
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_DOWN:
+ self.layerSelect.setValue(self.layerSelect.getValue() - 1)
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_PAGEUP:
+ self.layerSelect.setValue(self.layerSelect.getValue() + 10)
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_PAGEDOWN:
+ self.layerSelect.setValue(self.layerSelect.getValue() - 10)
+ self.QueueRefresh()
+ else:
+ if keyCode == wx.WXK_UP:
+ if wx.GetKeyState(wx.WXK_SHIFT):
+ self._zoom /= 1.2
+ if self._zoom < 1:
+ self._zoom = 1
+ else:
+ self._pitch -= 15
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_DOWN:
+ if wx.GetKeyState(wx.WXK_SHIFT):
+ self._zoom *= 1.2
+ if self._zoom > numpy.max(self._machineSize) * 3:
+ self._zoom = numpy.max(self._machineSize) * 3
+ else:
+ self._pitch += 15
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_LEFT:
+ self._yaw -= 15
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_RIGHT:
+ self._yaw += 15
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_NUMPAD_ADD or keyCode == wx.WXK_ADD or keyCode == ord('+') or keyCode == ord('='):
+ self._zoom /= 1.2
+ if self._zoom < 1:
+ self._zoom = 1
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_NUMPAD_SUBTRACT or keyCode == wx.WXK_SUBTRACT or keyCode == ord('-'):
+ self._zoom *= 1.2
+ if self._zoom > numpy.max(self._machineSize) * 3:
+ self._zoom = numpy.max(self._machineSize) * 3
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_HOME:
+ self._yaw = 30
+ self._pitch = 60
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_PAGEUP:
+ self._yaw = 0
+ self._pitch = 0
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_PAGEDOWN:
+ self._yaw = 0
+ self._pitch = 90
+ self.QueueRefresh()
+ elif keyCode == wx.WXK_END:
+ self._yaw = 90
+ self._pitch = 90
+ self.QueueRefresh()
if keyCode == wx.WXK_F3 and wx.GetKeyState(wx.WXK_SHIFT):
shaderEditor(self, self.ShaderUpdate, self._objectLoadShader.getVertexShader(), self._objectLoadShader.getFragmentShader())
if e.GetButton() == 3:
menu = wx.Menu()
if self._focusObj is not None:
- self.Bind(wx.EVT_MENU, lambda e: self._deleteObject(self._focusObj), menu.Append(-1, _("Delete")))
- self.Bind(wx.EVT_MENU, self.OnMultiply, menu.Append(-1, _("Multiply")))
- self.Bind(wx.EVT_MENU, self.OnSplitObject, menu.Append(-1, _("Split")))
+ self.Bind(wx.EVT_MENU, lambda e: self._deleteObject(self._focusObj), menu.Append(-1, _("Delete object")))
+ self.Bind(wx.EVT_MENU, self.OnCenter, menu.Append(-1, _("Center on platform")))
+ self.Bind(wx.EVT_MENU, self.OnMultiply, menu.Append(-1, _("Multiply object")))
+ self.Bind(wx.EVT_MENU, self.OnSplitObject, menu.Append(-1, _("Split object into parts")))
if ((self._selectedObj != self._focusObj and self._focusObj is not None and self._selectedObj is not None) or len(self._scene.objects()) == 2) and int(profile.getMachineSetting('extruder_amount')) > 1:
self.Bind(wx.EVT_MENU, self.OnMergeObjects, menu.Append(-1, _("Dual extrusion merge")))
if len(self._scene.objects()) > 0:
- self.Bind(wx.EVT_MENU, self.OnDeleteAll, menu.Append(-1, _("Delete all")))
+ self.Bind(wx.EVT_MENU, self.OnDeleteAll, menu.Append(-1, _("Delete all objects")))
if menu.MenuItemCount > 0:
self.PopupMenu(menu)
menu.Destroy()
elif self._mouseState == 'dragObject' and self._selectedObj is not None:
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self.sceneUpdated()
elif self._mouseState == 'tool':
if self.tempMatrix is not None and self._selectedObj is not None:
self._selectedObj.applyMatrix(self.tempMatrix)
- self._scene.pushFree()
+ self._scene.pushFree(self._selectedObj)
self._selectObject(self._selectedObj)
self.tempMatrix = None
self.tool.OnDragEnd()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
def OnPaint(self,e):
+ connectionGroup = self._printerConnectionManager.getAvailableGroup()
if machineCom.machineIsConnected():
self.printButton._imageID = 6
self.printButton._tooltip = _("Print")
- elif len(removableStorage.getPossibleSDcardDrives()) > 0:
+ elif len(removableStorage.getPossibleSDcardDrives()) > 0 and (connectionGroup is None or connectionGroup.getPriority() < 0):
self.printButton._imageID = 2
self.printButton._tooltip = _("Toolpath to SD")
+ elif connectionGroup is not None:
+ self.printButton._imageID = connectionGroup.getIconID()
+ self.printButton._tooltip = _("Print with %s") % (connectionGroup.getName())
else:
self.printButton._imageID = 3
self.printButton._tooltip = _("Save toolpath")
gl_FragColor = vec4(gl_Color.xyz * light_amount, 1.0-intensity);
}
""")
- if self._objectShader == None or not self._objectShader.isValid():
+ if self._objectShader is None or not self._objectShader.isValid():
self._objectShader = opengl.GLFakeShader()
self._objectOverhangShader = opengl.GLFakeShader()
self._objectLoadShader = None
self._drawMachine()
if self._usbPrintMonitor.getState() == 'PRINTING' and self._usbPrintMonitor.getID() == self._slicer.getID():
- glEnable(GL_BLEND)
z = self._usbPrintMonitor.getZ()
- size = self._machineSize
- glColor4ub(255,255,0,128)
- glBegin(GL_QUADS)
- glVertex3f(-size[0]/2,-size[1]/2, z)
- glVertex3f( size[0]/2,-size[1]/2, z)
- glVertex3f( size[0]/2, size[1]/2, z)
- glVertex3f(-size[0]/2, size[1]/2, z)
- glEnd()
+ if self.viewMode == 'gcode':
+ layer_height = profile.getProfileSettingFloat('layer_height')
+ layer1_height = profile.getProfileSettingFloat('bottom_thickness')
+ if layer_height > 0:
+ if layer1_height > 0:
+ layer = int((z - layer1_height) / layer_height) + 1
+ else:
+ layer = int(z / layer_height)
+ else:
+ layer = 1
+ self.layerSelect.setValue(layer)
+ else:
+ size = self._machineSize
+ glEnable(GL_BLEND)
+ glColor4ub(255,255,0,128)
+ glBegin(GL_QUADS)
+ glVertex3f(-size[0]/2,-size[1]/2, z)
+ glVertex3f( size[0]/2,-size[1]/2, z)
+ glVertex3f( size[0]/2, size[1]/2, z)
+ glVertex3f(-size[0]/2, size[1]/2, z)
+ glEnd()
if self.viewMode == 'gcode':
if self._gcodeLoadThread is not None and self._gcodeLoadThread.isAlive():
glPopMatrix()
else:
#Draw the object box-shadow, so you can see where it will collide with other objects.
- if self._selectedObj is not None and len(self._scene.objects()) > 1:
- size = self._selectedObj.getSize()[0:2] / 2 + self._scene.getObjectExtend()
- glPushMatrix()
- glTranslatef(self._selectedObj.getPosition()[0], self._selectedObj.getPosition()[1], 0)
+ if self._selectedObj is not None:
glEnable(GL_BLEND)
glEnable(GL_CULL_FACE)
- glColor4f(0,0,0,0.12)
- glBegin(GL_QUADS)
- glVertex3f(-size[0], size[1], 0.1)
- glVertex3f(-size[0], -size[1], 0.1)
- glVertex3f( size[0], -size[1], 0.1)
- glVertex3f( size[0], size[1], 0.1)
- glEnd()
+ glColor4f(0,0,0,0.16)
+ glDepthMask(False)
+ for obj in self._scene.objects():
+ glPushMatrix()
+ glTranslatef(obj.getPosition()[0], obj.getPosition()[1], 0)
+ glBegin(GL_TRIANGLE_FAN)
+ for p in obj._boundaryHull[::-1]:
+ glVertex3f(p[0], p[1], 0)
+ glEnd()
+ glPopMatrix()
+ if self._scene.isOneAtATime():
+ glPushMatrix()
+ glColor4f(0,0,0,0.06)
+ glTranslatef(self._selectedObj.getPosition()[0], self._selectedObj.getPosition()[1], 0)
+ glBegin(GL_TRIANGLE_FAN)
+ for p in self._selectedObj._printAreaHull[::-1]:
+ glVertex3f(p[0], p[1], 0)
+ glEnd()
+ glBegin(GL_TRIANGLE_FAN)
+ for p in self._selectedObj._headAreaMinHull[::-1]:
+ glVertex3f(p[0], p[1], 0)
+ glEnd()
+ glPopMatrix()
+ glDepthMask(True)
glDisable(GL_CULL_FACE)
- glPopMatrix()
#Draw the outline of the selected object, on top of everything else except the GUI.
if self._selectedObj is not None and self._selectedObj._loadAnim is None:
size = [profile.getMachineSettingFloat('machine_width'), profile.getMachineSettingFloat('machine_depth'), profile.getMachineSettingFloat('machine_height')]
machine = profile.getMachineSetting('machine_type')
- if profile.getMachineSetting('machine_type').startswith('ultimaker'):
+ if machine.startswith('ultimaker'):
if machine not in self._platformMesh:
meshes = meshLoader.loadMeshes(resources.getPathForMesh(machine + '_platform.stl'))
if len(meshes) > 0:
self._platformMesh[machine] = meshes[0]
else:
self._platformMesh[machine] = None
- if profile.getMachineSetting('machine_type') == 'ultimaker2':
+ if machine == 'ultimaker2':
self._platformMesh[machine]._drawOffset = numpy.array([0,-37,145], numpy.float32)
else:
self._platformMesh[machine]._drawOffset = numpy.array([0,0,2.5], numpy.float32)
self._objectShader.bind()
self._renderObject(self._platformMesh[machine], False, False)
self._objectShader.unbind()
+
+ #For the Ultimaker 2 render the texture on the back plate to show the Ultimaker2 text.
+ if machine == 'ultimaker2':
+ if not hasattr(self._platformMesh[machine], 'texture'):
+ self._platformMesh[machine].texture = opengl.loadGLTexture('Ultimaker2backplate.png')
+ glBindTexture(GL_TEXTURE_2D, self._platformMesh[machine].texture)
+ glEnable(GL_TEXTURE_2D)
+ glPushMatrix()
+ glColor4f(1,1,1,1)
+
+ glTranslate(0,150,-5)
+ h = 50
+ d = 8
+ w = 100
+ glEnable(GL_BLEND)
+ glBlendFunc(GL_DST_COLOR, GL_ZERO)
+ glBegin(GL_QUADS)
+ glTexCoord2f(1, 0)
+ glVertex3f( w, 0, h)
+ glTexCoord2f(0, 0)
+ glVertex3f(-w, 0, h)
+ glTexCoord2f(0, 1)
+ glVertex3f(-w, 0, 0)
+ glTexCoord2f(1, 1)
+ glVertex3f( w, 0, 0)
+
+ glTexCoord2f(1, 0)
+ glVertex3f(-w, d, h)
+ glTexCoord2f(0, 0)
+ glVertex3f( w, d, h)
+ glTexCoord2f(0, 1)
+ glVertex3f( w, d, 0)
+ glTexCoord2f(1, 1)
+ glVertex3f(-w, d, 0)
+ glEnd()
+ glDisable(GL_TEXTURE_2D)
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+ glPopMatrix()
else:
glColor4f(0,0,0,1)
glLineWidth(3)
glVertex3f(-size[0] / 2, -size[1] / 2+10, 0)
glEnd()
- v0 = [ size[0] / 2, size[1] / 2, size[2]]
- v1 = [ size[0] / 2,-size[1] / 2, size[2]]
- v2 = [-size[0] / 2, size[1] / 2, size[2]]
- v3 = [-size[0] / 2,-size[1] / 2, size[2]]
- v4 = [ size[0] / 2, size[1] / 2, 0]
- v5 = [ size[0] / 2,-size[1] / 2, 0]
- v6 = [-size[0] / 2, size[1] / 2, 0]
- v7 = [-size[0] / 2,-size[1] / 2, 0]
-
- vList = [v0,v1,v3,v2, v1,v0,v4,v5, v2,v3,v7,v6, v0,v2,v6,v4, v3,v1,v5,v7]
- glEnableClientState(GL_VERTEX_ARRAY)
- glVertexPointer(3, GL_FLOAT, 3*4, vList)
-
- glColor4ub(5, 171, 231, 64)
- glDrawArrays(GL_QUADS, 0, 4)
- glColor4ub(5, 171, 231, 96)
- glDrawArrays(GL_QUADS, 4, 8)
+ glDepthMask(False)
+
+ polys = profile.getMachineSizePolygons()
+ height = profile.getMachineSettingFloat('machine_height')
+ glBegin(GL_QUADS)
+ for n in xrange(0, len(polys[0])):
+ if n % 2 == 0:
+ glColor4ub(5, 171, 231, 96)
+ else:
+ glColor4ub(5, 171, 231, 64)
+ glVertex3f(polys[0][n][0], polys[0][n][1], height)
+ glVertex3f(polys[0][n][0], polys[0][n][1], 0)
+ glVertex3f(polys[0][n-1][0], polys[0][n-1][1], 0)
+ glVertex3f(polys[0][n-1][0], polys[0][n-1][1], height)
+ glEnd()
glColor4ub(5, 171, 231, 128)
- glDrawArrays(GL_QUADS, 12, 8)
- glDisableClientState(GL_VERTEX_ARRAY)
-
- sx = self._machineSize[0]
- sy = self._machineSize[1]
- for x in xrange(-int(sx/20)-1, int(sx / 20) + 1):
- for y in xrange(-int(sx/20)-1, int(sy / 20) + 1):
- x1 = x * 10
- x2 = x1 + 10
- y1 = y * 10
- y2 = y1 + 10
- x1 = max(min(x1, sx/2), -sx/2)
- y1 = max(min(y1, sy/2), -sy/2)
- x2 = max(min(x2, sx/2), -sx/2)
- y2 = max(min(y2, sy/2), -sy/2)
- if (x & 1) == (y & 1):
- glColor4ub(5, 171, 231, 127)
- else:
- glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128)
- glBegin(GL_QUADS)
- glVertex3f(x1, y1, -0.02)
- glVertex3f(x2, y1, -0.02)
- glVertex3f(x2, y2, -0.02)
- glVertex3f(x1, y2, -0.02)
- glEnd()
+ glBegin(GL_TRIANGLE_FAN)
+ for p in polys[0][::-1]:
+ glVertex3f(p[0], p[1], height)
+ glEnd()
+
+ #Draw checkerboard
+ if self._platformTexture is None:
+ self._platformTexture = opengl.loadGLTexture('checkerboard.png')
+ glBindTexture(GL_TEXTURE_2D, self._platformTexture)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
+ glColor4f(1,1,1,0.5)
+ glBindTexture(GL_TEXTURE_2D, self._platformTexture)
+ glEnable(GL_TEXTURE_2D)
+ glBegin(GL_TRIANGLE_FAN)
+ for p in polys[0]:
+ glTexCoord2f(p[0]/20, p[1]/20)
+ glVertex3f(p[0], p[1], 0)
+ glEnd()
+ glDisable(GL_TEXTURE_2D)
+ glColor4ub(127, 127, 127, 200)
+ for poly in polys[1:]:
+ glBegin(GL_TRIANGLE_FAN)
+ for p in poly:
+ glTexCoord2f(p[0]/20, p[1]/20)
+ glVertex3f(p[0], p[1], 0)
+ glEnd()
+ glDepthMask(True)
glDisable(GL_BLEND)
glDisable(GL_CULL_FACE)