From: Ilya Kulakov Date: Wed, 5 Dec 2012 17:33:55 +0000 (+0700) Subject: Merge remote-tracking branch 'upstream/master' into macosx X-Git-Tag: 13.03~175^2~3 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9f3d727817796e3aef04c5193e4b48ed09f19383;p=cura.git Merge remote-tracking branch 'upstream/master' into macosx Conflicts: Cura/gui/configWizard.py Cura/gui/mainWindow.py Cura/gui/opengl.py Cura/gui/printWindow.py scripts/osx64/Cura.app/Contents/MacOS/Cura --- 9f3d727817796e3aef04c5193e4b48ed09f19383 diff --cc Cura/gui/configWizard.py index daed5adb,08ca7c7b..54d734a2 --- a/Cura/gui/configWizard.py +++ b/Cura/gui/configWizard.py @@@ -1,667 -1,680 +1,714 @@@ - # coding=utf-8 - from __future__ import absolute_import - - import webbrowser - import threading - import time - - import wx - import wx.wizard - - from gui import firmwareInstall - from gui import toolbarUtil - from util import machineCom - from util import profile - from util.resources import getPathForImage - - class InfoBox(wx.Panel): - def __init__(self, parent): - super(InfoBox, self).__init__(parent) - self.SetBackgroundColour('#FFFF80') - - self.sizer = wx.GridBagSizer(5, 5) - self.SetSizer(self.sizer) - - self.attentionBitmap = wx.Bitmap(getPathForImage('attention.png')) - self.errorBitmap = wx.Bitmap(getPathForImage('error.png')) - self.readyBitmap = wx.Bitmap(getPathForImage('ready.png')) - self.busyBitmap = [ - wx.Bitmap(getPathForImage('busy-0.png')), - wx.Bitmap(getPathForImage('busy-1.png')), - wx.Bitmap(getPathForImage('busy-2.png')), - wx.Bitmap(getPathForImage('busy-3.png')) - ] - - self.bitmap = wx.StaticBitmap(self, -1, wx.EmptyBitmapRGBA(24, 24, red=255, green=255, blue=255, alpha=1)) - self.text = wx.StaticText(self, -1, '') - self.sizer.Add(self.bitmap, pos=(0, 0), flag=wx.ALL, border=5) - self.sizer.Add(self.text, pos=(0, 1), flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, border=5) - - self.busyState = None - self.timer = wx.Timer(self) - self.Bind(wx.EVT_TIMER, self.doBusyUpdate, self.timer) - self.timer.Start(100) - - def SetInfo(self, info): - self.SetBackgroundColour('#FFFF80') - self.text.SetLabel(info) - self.Refresh() - - def SetError(self, info): - self.SetBackgroundColour('#FF8080') - self.text.SetLabel(info) - self.SetErrorIndicator() - self.Refresh() - - def SetAttention(self, info): - self.SetBackgroundColour('#FFFF80') - self.text.SetLabel(info) - self.SetAttentionIndicator() - self.Refresh() - - def SetBusyIndicator(self): - self.busyState = 0 - self.bitmap.SetBitmap(self.busyBitmap[self.busyState]) - - def doBusyUpdate(self, e): - if self.busyState == None: - return - self.busyState += 1 - if self.busyState >= len(self.busyBitmap): - self.busyState = 0 - self.bitmap.SetBitmap(self.busyBitmap[self.busyState]) - - def SetReadyIndicator(self): - self.busyState = None - self.bitmap.SetBitmap(self.readyBitmap) - - def SetErrorIndicator(self): - self.busyState = None - self.bitmap.SetBitmap(self.errorBitmap) - - def SetAttentionIndicator(self): - self.busyState = None - self.bitmap.SetBitmap(self.attentionBitmap) - - - class InfoPage(wx.wizard.WizardPageSimple): - def __init__(self, parent, title): - wx.wizard.WizardPageSimple.__init__(self, parent) - - sizer = wx.GridBagSizer(5, 5) - self.sizer = sizer - self.SetSizer(sizer) - - title = wx.StaticText(self, -1, title) - title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD)) - sizer.Add(title, pos=(0, 0), span=(1, 2), flag=wx.ALIGN_CENTRE | wx.ALL) - sizer.Add(wx.StaticLine(self, -1), pos=(1, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) - sizer.AddGrowableCol(1) - - self.rowNr = 2 - - def AddText(self, info): - text = wx.StaticText(self, -1, info) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT) - self.rowNr += 1 - return text - - def AddSeperator(self): - self.GetSizer().Add(wx.StaticLine(self, -1), pos=(self.rowNr, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) - self.rowNr += 1 - - def AddHiddenSeperator(self): - self.AddText('') - - def AddInfoBox(self): - infoBox = InfoBox(self) - self.GetSizer().Add(infoBox, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT | wx.EXPAND) - self.rowNr += 1 - return infoBox - - def AddRadioButton(self, label, style=0): - radio = wx.RadioButton(self, -1, label, style=style) - self.GetSizer().Add(radio, pos=(self.rowNr, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) - self.rowNr += 1 - return radio - - def AddCheckbox(self, label, checked=False): - check = wx.CheckBox(self, -1) - text = wx.StaticText(self, -1, label) - check.SetValue(checked) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT | wx.RIGHT) - self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1, 2), flag=wx.ALL) - self.rowNr += 1 - return check - - def AddButton(self, label): - button = wx.Button(self, -1, label) - self.GetSizer().Add(button, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT) - self.rowNr += 1 - return button - - def AddDualButton(self, label1, label2): - button1 = wx.Button(self, -1, label1) - self.GetSizer().Add(button1, pos=(self.rowNr, 0), flag=wx.RIGHT) - button2 = wx.Button(self, -1, label2) - self.GetSizer().Add(button2, pos=(self.rowNr, 1)) - self.rowNr += 1 - return button1, button2 - - def AddTextCtrl(self, value): - ret = wx.TextCtrl(self, -1, value) - self.GetSizer().Add(ret, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT) - self.rowNr += 1 - return ret - - def AddLabelTextCtrl(self, info, value): - text = wx.StaticText(self, -1, info) - ret = wx.TextCtrl(self, -1, value) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT) - self.GetSizer().Add(ret, pos=(self.rowNr, 1), span=(1, 1), flag=wx.LEFT) - self.rowNr += 1 - return ret - - def AddTextCtrlButton(self, value, buttonText): - text = wx.TextCtrl(self, -1, value) - button = wx.Button(self, -1, buttonText) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT) - self.GetSizer().Add(button, pos=(self.rowNr, 1), span=(1, 1), flag=wx.LEFT) - self.rowNr += 1 - return text, button - - def AddBitmap(self, bitmap): - bitmap = wx.StaticBitmap(self, -1, bitmap) - self.GetSizer().Add(bitmap, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT) - self.rowNr += 1 - return bitmap - - def AddCheckmark(self, label, bitmap): - check = wx.StaticBitmap(self, -1, bitmap) - text = wx.StaticText(self, -1, label) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT | wx.RIGHT) - self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1, 1), flag=wx.ALL) - self.rowNr += 1 - return check - - def AllowNext(self): - return True - - def StoreData(self): - pass - - - class FirstInfoPage(InfoPage): - def __init__(self, parent): - super(FirstInfoPage, self).__init__(parent, "First time run wizard") - self.AddText('Welcome, and thanks for trying Cura!') - self.AddSeperator() - self.AddText('This wizard will help you with the following steps:') - self.AddText('* Configure Cura for your machine') - self.AddText('* Upgrade your firmware') - self.AddText('* Check if your machine is working safely') - - #self.AddText('* Calibrate your machine') - #self.AddText('* Do your first print') - - - class RepRapInfoPage(InfoPage): - def __init__(self, parent): - super(RepRapInfoPage, self).__init__(parent, "RepRap information") - self.AddText( - 'RepRap machines are vastly different, and there is no\ndefault configuration in Cura for any of them.') - self.AddText('If you like a default profile for your machine added,\nthen make an issue on github.') - self.AddSeperator() - self.AddText('You will have to manually install Marlin or Sprinter firmware.') - self.AddSeperator() - self.machineWidth = self.AddLabelTextCtrl('Machine width (mm)', '80') - self.machineDepth = self.AddLabelTextCtrl('Machine depth (mm)', '80') - self.machineHeight = self.AddLabelTextCtrl('Machine height (mm)', '60') - self.nozzleSize = self.AddLabelTextCtrl('Nozzle size (mm)', '0.5') - self.heatedBed = self.AddCheckbox('Heated bed') - - def StoreData(self): - profile.putPreference('machine_width', self.machineWidth.GetValue()) - profile.putPreference('machine_depth', self.machineDepth.GetValue()) - profile.putPreference('machine_height', self.machineHeight.GetValue()) - profile.putProfileSetting('nozzle_size', self.nozzleSize.GetValue()) - profile.putProfileSetting('machine_center_x', profile.getPreferenceFloat('machine_width') / 2) - profile.putProfileSetting('machine_center_y', profile.getPreferenceFloat('machine_depth') / 2) - profile.putProfileSetting('wall_thickness', float(profile.getProfileSettingFloat('nozzle_size')) * 2) - profile.putPreference('has_heated_bed', str(self.heatedBed.GetValue())) - - - class MachineSelectPage(InfoPage): - def __init__(self, parent): - super(MachineSelectPage, self).__init__(parent, "Select your machine") - self.AddText('What kind of machine do you have:') - - self.UltimakerRadio = self.AddRadioButton("Ultimaker", style=wx.RB_GROUP) - self.UltimakerRadio.SetValue(True) - self.UltimakerRadio.Bind(wx.EVT_RADIOBUTTON, self.OnUltimakerSelect) - self.OtherRadio = self.AddRadioButton("Other (Ex: RepRap)") - self.OtherRadio.Bind(wx.EVT_RADIOBUTTON, self.OnOtherSelect) - - def OnUltimakerSelect(self, e): - wx.wizard.WizardPageSimple.Chain(self, self.GetParent().ultimakerFirmwareUpgradePage) - - def OnOtherSelect(self, e): - wx.wizard.WizardPageSimple.Chain(self, self.GetParent().repRapInfoPage) - - def StoreData(self): - if self.UltimakerRadio.GetValue(): - profile.putPreference('machine_width', '205') - profile.putPreference('machine_depth', '205') - profile.putPreference('machine_height', '200') - profile.putPreference('machine_type', 'ultimaker') - profile.putProfileSetting('nozzle_size', '0.4') - profile.putProfileSetting('machine_center_x', '100') - profile.putProfileSetting('machine_center_y', '100') - else: - profile.putPreference('machine_width', '80') - profile.putPreference('machine_depth', '80') - profile.putPreference('machine_height', '60') - profile.putPreference('machine_type', 'reprap') - profile.putPreference('startMode', 'Normal') - profile.putProfileSetting('nozzle_size', '0.5') - profile.putProfileSetting('machine_center_x', '40') - profile.putProfileSetting('machine_center_y', '40') - profile.putProfileSetting('wall_thickness', float(profile.getProfileSetting('nozzle_size')) * 2) - - - class FirmwareUpgradePage(InfoPage): - def __init__(self, parent): - super(FirmwareUpgradePage, self).__init__(parent, "Upgrade Ultimaker Firmware") - self.AddText( - 'Firmware is the piece of software running directly on your 3D printer.\nThis firmware controls the step motors, regulates the temperature\nand ultimately makes your printer work.') - self.AddHiddenSeperator() - self.AddText( - 'The firmware shipping with new Ultimakers works, but upgrades\nhave been made to make better prints, and make calibration easier.') - self.AddHiddenSeperator() - self.AddText( - 'Cura requires these new features and thus\nyour firmware will most likely need to be upgraded.\nYou will get the chance to do so now.') - upgradeButton, skipUpgradeButton = self.AddDualButton('Upgrade to Marlin firmware', 'Skip upgrade') - upgradeButton.Bind(wx.EVT_BUTTON, self.OnUpgradeClick) - skipUpgradeButton.Bind(wx.EVT_BUTTON, self.OnSkipClick) - self.AddHiddenSeperator() - self.AddText('Do not upgrade to this firmware if:') - self.AddText('* You have an older machine based on ATMega1280') - self.AddText('* Have other changes in the firmware') - button = self.AddButton('Goto this page for a custom firmware') - button.Bind(wx.EVT_BUTTON, self.OnUrlClick) - - def AllowNext(self): - return False - - def OnUpgradeClick(self, e): - if firmwareInstall.InstallFirmware(): - self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - - def OnSkipClick(self, e): - self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - - def OnUrlClick(self, e): - webbrowser.open('http://daid.mine.nu/~daid/marlin_build/') - - - class UltimakerCheckupPage(InfoPage): - def __init__(self, parent): - super(UltimakerCheckupPage, self).__init__(parent, "Ultimaker Checkup") - - self.checkBitmap = wx.Bitmap(getPathForImage('checkmark.png')) - self.crossBitmap = wx.Bitmap(getPathForImage('cross.png')) - self.unknownBitmap = wx.Bitmap(getPathForImage('question.png')) - self.endStopNoneBitmap = wx.Bitmap(getPathForImage('endstop_none.png')) - self.endStopXMinBitmap = wx.Bitmap(getPathForImage('endstop_xmin.png')) - self.endStopXMaxBitmap = wx.Bitmap(getPathForImage('endstop_xmax.png')) - self.endStopYMinBitmap = wx.Bitmap(getPathForImage('endstop_ymin.png')) - self.endStopYMaxBitmap = wx.Bitmap(getPathForImage('endstop_ymax.png')) - self.endStopZMinBitmap = wx.Bitmap(getPathForImage('endstop_zmin.png')) - self.endStopZMaxBitmap = wx.Bitmap(getPathForImage('endstop_zmax.png')) - - self.AddText( - 'It is a good idea to do a few sanity checks now on your Ultimaker.\nYou can skip these if you know your machine is functional.') - b1, b2 = self.AddDualButton('Run checks', 'Skip checks') - b1.Bind(wx.EVT_BUTTON, self.OnCheckClick) - b2.Bind(wx.EVT_BUTTON, self.OnSkipClick) - self.AddSeperator() - self.commState = self.AddCheckmark('Communication:', self.unknownBitmap) - self.tempState = self.AddCheckmark('Temperature:', self.unknownBitmap) - self.stopState = self.AddCheckmark('Endstops:', self.unknownBitmap) - self.AddSeperator() - self.infoBox = self.AddInfoBox() - self.machineState = self.AddText('') - self.temperatureLabel = self.AddText('') - self.AddSeperator() - self.endstopBitmap = self.AddBitmap(self.endStopNoneBitmap) - self.comm = None - self.xMinStop = False - self.xMaxStop = False - self.yMinStop = False - self.yMaxStop = False - self.zMinStop = False - self.zMaxStop = False - - def __del__(self): - if self.comm != None: - self.comm.close() - - def AllowNext(self): - self.endstopBitmap.Show(False) - return False - - def OnSkipClick(self, e): - self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - - def OnCheckClick(self, e=None): - if self.comm != None: - self.comm.close() - del self.comm - self.comm = None - wx.CallAfter(self.OnCheckClick) - return - self.infoBox.SetInfo('Connecting to machine.') - self.infoBox.SetBusyIndicator() - self.commState.SetBitmap(self.unknownBitmap) - self.tempState.SetBitmap(self.unknownBitmap) - self.stopState.SetBitmap(self.unknownBitmap) - self.checkupState = 0 - self.comm = machineCom.MachineCom(callbackObject=self) - - def mcLog(self, message): - pass - - def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp): - if not self.comm.isOperational(): - return - if self.checkupState == 0: - self.tempCheckTimeout = 20 - if temp > 70: - self.checkupState = 1 - wx.CallAfter(self.infoBox.SetInfo, 'Cooldown before temperature check.') - self.comm.sendCommand('M104 S0') - self.comm.sendCommand('M104 S0') - else: - self.startTemp = temp - self.checkupState = 2 - wx.CallAfter(self.infoBox.SetInfo, 'Checking the heater and temperature sensor.') - self.comm.sendCommand('M104 S200') - self.comm.sendCommand('M104 S200') - elif self.checkupState == 1: - if temp < 60: - self.startTemp = temp - self.checkupState = 2 - wx.CallAfter(self.infoBox.SetInfo, 'Checking the heater and temperature sensor.') - self.comm.sendCommand('M104 S200') - self.comm.sendCommand('M104 S200') - elif self.checkupState == 2: - #print "WARNING, TEMPERATURE TEST DISABLED FOR TESTING!" - if temp > self.startTemp + 40: - self.checkupState = 3 - wx.CallAfter(self.infoBox.SetAttention, 'Please make sure none of the endstops are pressed.') - wx.CallAfter(self.endstopBitmap.Show, True) - wx.CallAfter(self.Layout) - self.comm.sendCommand('M104 S0') - self.comm.sendCommand('M104 S0') - self.comm.sendCommand('M119') - wx.CallAfter(self.tempState.SetBitmap, self.checkBitmap) - else: - self.tempCheckTimeout -= 1 - if self.tempCheckTimeout < 1: - self.checkupState = -1 - wx.CallAfter(self.tempState.SetBitmap, self.crossBitmap) - wx.CallAfter(self.infoBox.SetError, 'Temperature measurement FAILED!') - self.comm.sendCommand('M104 S0') - self.comm.sendCommand('M104 S0') - wx.CallAfter(self.temperatureLabel.SetLabel, 'Head temperature: %d' % (temp)) - - def mcStateChange(self, state): - if self.comm == None: - return - if self.comm.isOperational(): - wx.CallAfter(self.commState.SetBitmap, self.checkBitmap) - elif self.comm.isError(): - wx.CallAfter(self.commState.SetBitmap, self.crossBitmap) - wx.CallAfter(self.infoBox.SetError, 'Failed to establish connection with the printer.') - wx.CallAfter(self.endstopBitmap.Show, False) - wx.CallAfter(self.machineState.SetLabel, 'Communication State: %s' % (self.comm.getStateString())) - - def mcMessage(self, message): - if self.checkupState >= 3 and self.checkupState < 10 and 'x_min' in message: - for data in message.split(' '): - if ':' in data: - tag, value = data.split(':', 2) - if tag == 'x_min': - self.xMinStop = (value == 'H') - if tag == 'x_max': - self.xMaxStop = (value == 'H') - if tag == 'y_min': - self.yMinStop = (value == 'H') - if tag == 'y_max': - self.yMaxStop = (value == 'H') - if tag == 'z_min': - self.zMinStop = (value == 'H') - if tag == 'z_max': - self.zMaxStop = (value == 'H') - self.comm.sendCommand('M119') - - if self.checkupState == 3: - if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: - self.checkupState = 4 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the right X endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopXMaxBitmap) - elif self.checkupState == 4: - if not self.xMinStop and self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: - self.checkupState = 5 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the left X endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopXMinBitmap) - elif self.checkupState == 5: - if self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: - self.checkupState = 6 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the front Y endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopYMinBitmap) - elif self.checkupState == 6: - if not self.xMinStop and not self.xMaxStop and self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: - self.checkupState = 7 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the back Y endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopYMaxBitmap) - elif self.checkupState == 7: - if not self.xMinStop and not self.xMaxStop and not self.yMinStop and self.yMaxStop and not self.zMinStop and not self.zMaxStop: - self.checkupState = 8 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the top Z endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopZMinBitmap) - elif self.checkupState == 8: - if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and self.zMinStop and not self.zMaxStop: - self.checkupState = 9 - wx.CallAfter(self.infoBox.SetAttention, 'Please press the bottom Z endstop.') - wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopZMaxBitmap) - elif self.checkupState == 9: - if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and self.zMaxStop: - self.checkupState = 10 - self.comm.close() - wx.CallAfter(self.infoBox.SetInfo, 'Checkup finished') - wx.CallAfter(self.infoBox.SetReadyIndicator) - wx.CallAfter(self.endstopBitmap.Show, False) - wx.CallAfter(self.stopState.SetBitmap, self.checkBitmap) - wx.CallAfter(self.OnSkipClick, None) - - def mcProgress(self, lineNr): - pass - - def mcZChange(self, newZ): - pass - - - class UltimakerCalibrationPage(InfoPage): - def __init__(self, parent): - super(UltimakerCalibrationPage, self).__init__(parent, "Ultimaker Calibration") - - self.AddText("Your Ultimaker requires some calibration.") - self.AddText("This calibration is needed for a proper extrusion amount.") - self.AddSeperator() - self.AddText("The following values are needed:") - self.AddText("* Diameter of filament") - self.AddText("* Number of steps per mm of filament extrusion") - self.AddSeperator() - self.AddText("The better you have calibrated these values, the better your prints\nwill become.") - self.AddSeperator() - self.AddText("First we need the diameter of your filament:") - self.filamentDiameter = self.AddTextCtrl(profile.getProfileSetting('filament_diameter')) - self.AddText( - "If you do not own digital Calipers that can measure\nat least 2 digits then use 2.89mm.\nWhich is the average diameter of most filament.") - self.AddText("Note: This value can be changed later at any time.") - - def StoreData(self): - profile.putProfileSetting('filament_diameter', self.filamentDiameter.GetValue()) - - - class UltimakerCalibrateStepsPerEPage(InfoPage): - def __init__(self, parent): - super(UltimakerCalibrateStepsPerEPage, self).__init__(parent, "Ultimaker Calibration") - - if profile.getPreference('steps_per_e') == '0': - profile.putPreference('steps_per_e', '865.888') - - self.AddText("Calibrating the Steps Per E requires some manual actions.") - self.AddText("First remove any filament from your machine.") - self.AddText("Next put in your filament so the tip is aligned with the\ntop of the extruder drive.") - self.AddText("We'll push the filament 100mm") - self.extrudeButton = self.AddButton("Extrude 100mm filament") - self.AddText("Now measure the amount of extruded filament:\n(this can be more or less then 100mm)") - self.lengthInput, self.saveLengthButton = self.AddTextCtrlButton('100', 'Save') - self.AddText("This results in the following steps per E:") - self.stepsPerEInput = self.AddTextCtrl(profile.getPreference('steps_per_e')) - self.AddText("You can repeat these steps to get better calibration.") - self.AddSeperator() - self.AddText( - "If you still have filament in your printer which needs\nheat to remove, press the heat up button below:") - self.heatButton = self.AddButton("Heatup for filament removal") - - self.saveLengthButton.Bind(wx.EVT_BUTTON, self.OnSaveLengthClick) - self.extrudeButton.Bind(wx.EVT_BUTTON, self.OnExtrudeClick) - self.heatButton.Bind(wx.EVT_BUTTON, self.OnHeatClick) - - def OnSaveLengthClick(self, e): - currentEValue = float(self.stepsPerEInput.GetValue()) - realExtrudeLength = float(self.lengthInput.GetValue()) - newEValue = currentEValue * 100 / realExtrudeLength - self.stepsPerEInput.SetValue(str(newEValue)) - self.lengthInput.SetValue("100") - - def OnExtrudeClick(self, e): - threading.Thread(target=self.OnExtrudeRun).start() - - def OnExtrudeRun(self): - self.heatButton.Enable(False) - self.extrudeButton.Enable(False) - currentEValue = float(self.stepsPerEInput.GetValue()) - self.comm = machineCom.MachineCom() - if not self.comm.isOpen(): - wx.MessageBox( - "Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", - 'Printer error', wx.OK | wx.ICON_INFORMATION) - self.heatButton.Enable(True) - self.extrudeButton.Enable(True) - return - while True: - line = self.comm.readline() - if line == '': - return - if 'start' in line: - break - #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. - time.sleep(3) - - self.sendGCommand('M302') #Disable cold extrusion protection - self.sendGCommand("M92 E%f" % (currentEValue)) - self.sendGCommand("G92 E0") - self.sendGCommand("G1 E100 F600") - time.sleep(15) - self.comm.close() - self.extrudeButton.Enable() - self.heatButton.Enable() - - def OnHeatClick(self, e): - threading.Thread(target=self.OnHeatRun).start() - - def OnHeatRun(self): - self.heatButton.Enable(False) - self.extrudeButton.Enable(False) - self.comm = machineCom.MachineCom() - if not self.comm.isOpen(): - wx.MessageBox( - "Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", - 'Printer error', wx.OK | wx.ICON_INFORMATION) - self.heatButton.Enable(True) - self.extrudeButton.Enable(True) - return - while True: - line = self.comm.readline() - if line == '': - self.heatButton.Enable(True) - self.extrudeButton.Enable(True) - return - if 'start' in line: - break - #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. - time.sleep(3) - - self.sendGCommand('M104 S200') #Set the temperature to 200C, should be enough to get PLA and ABS out. - wx.MessageBox( - 'Wait till you can remove the filament from the machine, and press OK.\n(Temperature is set to 200C)', - 'Machine heatup', wx.OK | wx.ICON_INFORMATION) - self.sendGCommand('M104 S0') - time.sleep(1) - self.comm.close() - self.heatButton.Enable(True) - self.extrudeButton.Enable(True) - - def sendGCommand(self, cmd): - self.comm.sendCommand(cmd) #Disable cold extrusion protection - while True: - line = self.comm.readline() - if line == '': - return - if line.startswith('ok'): - break - - def StoreData(self): - profile.putPreference('steps_per_e', self.stepsPerEInput.GetValue()) - - - class configWizard(wx.wizard.Wizard): - def __init__(self): - super(configWizard, self).__init__(None, -1, "Configuration Wizard") - - self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGED, self.OnPageChanged) - self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging) - - self.firstInfoPage = FirstInfoPage(self) - self.machineSelectPage = MachineSelectPage(self) - self.ultimakerFirmwareUpgradePage = FirmwareUpgradePage(self) - self.ultimakerCheckupPage = UltimakerCheckupPage(self) - self.ultimakerCalibrationPage = UltimakerCalibrationPage(self) - self.ultimakerCalibrateStepsPerEPage = UltimakerCalibrateStepsPerEPage(self) - self.repRapInfoPage = RepRapInfoPage(self) - - wx.wizard.WizardPageSimple.Chain(self.firstInfoPage, self.machineSelectPage) - wx.wizard.WizardPageSimple.Chain(self.machineSelectPage, self.ultimakerFirmwareUpgradePage) - wx.wizard.WizardPageSimple.Chain(self.ultimakerFirmwareUpgradePage, self.ultimakerCheckupPage) - #wx.wizard.WizardPageSimple.Chain(self.ultimakerCheckupPage, self.ultimakerCalibrationPage) - #wx.wizard.WizardPageSimple.Chain(self.ultimakerCalibrationPage, self.ultimakerCalibrateStepsPerEPage) - - self.FitToPage(self.firstInfoPage) - self.GetPageAreaSizer().Add(self.firstInfoPage) - - self.RunWizard(self.firstInfoPage) - self.Destroy() - - def OnPageChanging(self, e): - e.GetPage().StoreData() - - def OnPageChanged(self, e): - if e.GetPage().AllowNext(): - self.FindWindowById(wx.ID_FORWARD).Enable() - else: - self.FindWindowById(wx.ID_FORWARD).Disable() - self.FindWindowById(wx.ID_BACKWARD).Disable() ++# coding=utf-8 + from __future__ import absolute_import -import __init__ + -import wx, os, platform, types, webbrowser, threading, time, re ++import webbrowser ++import threading ++import time ++ ++import wx + import wx.wizard + + from gui import firmwareInstall + from gui import toolbarUtil + from gui import printWindow + from util import machineCom + from util import profile ++from util.resources import getPathForImage + + class InfoBox(wx.Panel): + def __init__(self, parent): + super(InfoBox, self).__init__(parent) + self.SetBackgroundColour('#FFFF80') - ++ + self.sizer = wx.GridBagSizer(5, 5) + self.SetSizer(self.sizer) - - self.attentionBitmap = toolbarUtil.getBitmapImage('attention.png') - self.errorBitmap = toolbarUtil.getBitmapImage('error.png') - self.readyBitmap = toolbarUtil.getBitmapImage('ready.png') - self.busyBitmap = [toolbarUtil.getBitmapImage('busy-0.png'), toolbarUtil.getBitmapImage('busy-1.png'), toolbarUtil.getBitmapImage('busy-2.png'), toolbarUtil.getBitmapImage('busy-3.png')] - ++ ++ self.attentionBitmap = wx.Bitmap(getPathForImage('attention.png')) ++ self.errorBitmap = wx.Bitmap(getPathForImage('error.png')) ++ self.readyBitmap = wx.Bitmap(getPathForImage('ready.png')) ++ self.busyBitmap = [ ++ wx.Bitmap(getPathForImage('busy-0.png')), ++ wx.Bitmap(getPathForImage('busy-1.png')), ++ wx.Bitmap(getPathForImage('busy-2.png')), ++ wx.Bitmap(getPathForImage('busy-3.png')) ++ ] ++ + self.bitmap = wx.StaticBitmap(self, -1, wx.EmptyBitmapRGBA(24, 24, red=255, green=255, blue=255, alpha=1)) + self.text = wx.StaticText(self, -1, '') + self.extraInfoButton = wx.Button(self, -1, 'i', style=wx.BU_EXACTFIT) - self.sizer.Add(self.bitmap, pos=(0,0), flag=wx.ALL, border=5) - self.sizer.Add(self.text, pos=(0,1), flag=wx.TOP|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL, border=5) ++ self.sizer.Add(self.bitmap, pos=(0, 0), flag=wx.ALL, border=5) ++ self.sizer.Add(self.text, pos=(0, 1), flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, border=5) + self.sizer.Add(self.extraInfoButton, pos=(0,2), flag=wx.ALL|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, border=5) + self.sizer.AddGrowableCol(1) - ++ + self.extraInfoButton.Show(False) - ++ + self.extraInfoUrl = '' + self.busyState = None + self.timer = wx.Timer(self) + self.Bind(wx.EVT_TIMER, self.doBusyUpdate, self.timer) + self.Bind(wx.EVT_BUTTON, self.doExtraInfo, self.extraInfoButton) + self.timer.Start(100) + + def SetInfo(self, info): + self.SetBackgroundColour('#FFFF80') + self.text.SetLabel(info) + self.extraInfoButton.Show(False) + self.Refresh() + + def SetError(self, info, extraInfoUrl): + self.extraInfoUrl = extraInfoUrl + self.SetBackgroundColour('#FF8080') + self.text.SetLabel(info) + self.extraInfoButton.Show(True) + self.Layout() + self.SetErrorIndicator() + self.Refresh() - ++ + def SetAttention(self, info): + self.SetBackgroundColour('#FFFF80') + self.text.SetLabel(info) + self.extraInfoButton.Show(False) + self.SetAttentionIndicator() + self.Refresh() - ++ + def SetBusyIndicator(self): + self.busyState = 0 + self.bitmap.SetBitmap(self.busyBitmap[self.busyState]) - ++ ++ def doExtraInfo(self, e): ++ webbrowser.open(self.extraInfoUrl) ++ + def doBusyUpdate(self, e): + if self.busyState == None: + return + self.busyState += 1 + if self.busyState >= len(self.busyBitmap): + self.busyState = 0 + self.bitmap.SetBitmap(self.busyBitmap[self.busyState]) - - def doExtraInfo(self, e): - webbrowser.open(self.extraInfoUrl) - ++ + def SetReadyIndicator(self): + self.busyState = None + self.bitmap.SetBitmap(self.readyBitmap) - ++ + def SetErrorIndicator(self): + self.busyState = None + self.bitmap.SetBitmap(self.errorBitmap) - ++ + def SetAttentionIndicator(self): + self.busyState = None + self.bitmap.SetBitmap(self.attentionBitmap) + ++ + class InfoPage(wx.wizard.WizardPageSimple): + def __init__(self, parent, title): + wx.wizard.WizardPageSimple.__init__(self, parent) + + sizer = wx.GridBagSizer(5, 5) + self.sizer = sizer + self.SetSizer(sizer) + + title = wx.StaticText(self, -1, title) + title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD)) - sizer.Add(title, pos=(0, 0), span=(1,2), flag=wx.ALIGN_CENTRE|wx.ALL) - sizer.Add(wx.StaticLine(self, -1), pos=(1,0), span=(1,2), flag=wx.EXPAND|wx.ALL) ++ sizer.Add(title, pos=(0, 0), span=(1, 2), flag=wx.ALIGN_CENTRE | wx.ALL) ++ sizer.Add(wx.StaticLine(self, -1), pos=(1, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) + sizer.AddGrowableCol(1) - ++ + self.rowNr = 2 - - def AddText(self,info): ++ ++ def AddText(self, info): + text = wx.StaticText(self, -1, info) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1,2), flag=wx.LEFT|wx.RIGHT) ++ self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT) + self.rowNr += 1 + return text - ++ + def AddSeperator(self): - self.GetSizer().Add(wx.StaticLine(self, -1), pos=(self.rowNr, 0), span=(1,2), flag=wx.EXPAND|wx.ALL) ++ self.GetSizer().Add(wx.StaticLine(self, -1), pos=(self.rowNr, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) + self.rowNr += 1 - ++ + def AddHiddenSeperator(self): + self.AddText('') + + def AddInfoBox(self): + infoBox = InfoBox(self) - self.GetSizer().Add(infoBox, pos=(self.rowNr, 0), span=(1,2), flag=wx.LEFT|wx.RIGHT|wx.EXPAND) ++ self.GetSizer().Add(infoBox, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT | wx.EXPAND) + self.rowNr += 1 + return infoBox - - def AddRadioButton(self, label, style = 0): ++ ++ def AddRadioButton(self, label, style=0): + radio = wx.RadioButton(self, -1, label, style=style) - self.GetSizer().Add(radio, pos=(self.rowNr, 0), span=(1,2), flag=wx.EXPAND|wx.ALL) ++ self.GetSizer().Add(radio, pos=(self.rowNr, 0), span=(1, 2), flag=wx.EXPAND | wx.ALL) + self.rowNr += 1 + return radio + - def AddCheckbox(self, label, checked = False): ++ def AddCheckbox(self, label, checked=False): + check = wx.CheckBox(self, -1) + text = wx.StaticText(self, -1, label) + check.SetValue(checked) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1,1), flag=wx.LEFT|wx.RIGHT) - self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1,2), flag=wx.ALL) ++ self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT | wx.RIGHT) ++ self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1, 2), flag=wx.ALL) + self.rowNr += 1 + return check - ++ + def AddButton(self, label): + button = wx.Button(self, -1, label) - self.GetSizer().Add(button, pos=(self.rowNr, 0), span=(1,2), flag=wx.LEFT) ++ self.GetSizer().Add(button, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT) + self.rowNr += 1 + return button - ++ + def AddDualButton(self, label1, label2): + button1 = wx.Button(self, -1, label1) + self.GetSizer().Add(button1, pos=(self.rowNr, 0), flag=wx.RIGHT) + button2 = wx.Button(self, -1, label2) + self.GetSizer().Add(button2, pos=(self.rowNr, 1)) + self.rowNr += 1 + return button1, button2 - ++ + def AddTextCtrl(self, value): + ret = wx.TextCtrl(self, -1, value) - self.GetSizer().Add(ret, pos=(self.rowNr, 0), span=(1,2), flag=wx.LEFT) ++ self.GetSizer().Add(ret, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT) + self.rowNr += 1 + return ret + + def AddLabelTextCtrl(self, info, value): + text = wx.StaticText(self, -1, info) + ret = wx.TextCtrl(self, -1, value) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1,1), flag=wx.LEFT) - self.GetSizer().Add(ret, pos=(self.rowNr, 1), span=(1,1), flag=wx.LEFT) ++ self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT) ++ self.GetSizer().Add(ret, pos=(self.rowNr, 1), span=(1, 1), flag=wx.LEFT) + self.rowNr += 1 + return ret - ++ + def AddTextCtrlButton(self, value, buttonText): + text = wx.TextCtrl(self, -1, value) + button = wx.Button(self, -1, buttonText) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1,1), flag=wx.LEFT) - self.GetSizer().Add(button, pos=(self.rowNr, 1), span=(1,1), flag=wx.LEFT) ++ self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT) ++ self.GetSizer().Add(button, pos=(self.rowNr, 1), span=(1, 1), flag=wx.LEFT) + self.rowNr += 1 + return text, button + + def AddBitmap(self, bitmap): + bitmap = wx.StaticBitmap(self, -1, bitmap) - self.GetSizer().Add(bitmap, pos=(self.rowNr, 0), span=(1,2), flag=wx.LEFT|wx.RIGHT) ++ self.GetSizer().Add(bitmap, pos=(self.rowNr, 0), span=(1, 2), flag=wx.LEFT | wx.RIGHT) + self.rowNr += 1 + return bitmap + + def AddCheckmark(self, label, bitmap): + check = wx.StaticBitmap(self, -1, bitmap) + text = wx.StaticText(self, -1, label) - self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1,1), flag=wx.LEFT|wx.RIGHT) - self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1,1), flag=wx.ALL) ++ self.GetSizer().Add(text, pos=(self.rowNr, 0), span=(1, 1), flag=wx.LEFT | wx.RIGHT) ++ self.GetSizer().Add(check, pos=(self.rowNr, 1), span=(1, 1), flag=wx.ALL) + self.rowNr += 1 + return check - ++ + def AllowNext(self): + return True - ++ + def StoreData(self): + pass + ++ + class FirstInfoPage(InfoPage): + def __init__(self, parent): + super(FirstInfoPage, self).__init__(parent, "First time run wizard") + self.AddText('Welcome, and thanks for trying Cura!') + self.AddSeperator() + self.AddText('This wizard will help you with the following steps:') + self.AddText('* Configure Cura for your machine') + self.AddText('* Upgrade your firmware') + self.AddText('* Check if your machine is working safely') ++ + #self.AddText('* Calibrate your machine') + #self.AddText('* Do your first print') + ++ + class RepRapInfoPage(InfoPage): + def __init__(self, parent): + super(RepRapInfoPage, self).__init__(parent, "RepRap information") - self.AddText('RepRap machines are vastly different, and there is no\ndefault configuration in Cura for any of them.') ++ self.AddText( ++ 'RepRap machines are vastly different, and there is no\ndefault configuration in Cura for any of them.') + self.AddText('If you like a default profile for your machine added,\nthen make an issue on github.') + self.AddSeperator() + self.AddText('You will have to manually install Marlin or Sprinter firmware.') + self.AddSeperator() + self.machineWidth = self.AddLabelTextCtrl('Machine width (mm)', '80') + self.machineDepth = self.AddLabelTextCtrl('Machine depth (mm)', '80') + self.machineHeight = self.AddLabelTextCtrl('Machine height (mm)', '60') + self.nozzleSize = self.AddLabelTextCtrl('Nozzle size (mm)', '0.5') + self.heatedBed = self.AddCheckbox('Heated bed') + + def StoreData(self): + profile.putPreference('machine_width', self.machineWidth.GetValue()) + profile.putPreference('machine_depth', self.machineDepth.GetValue()) + profile.putPreference('machine_height', self.machineHeight.GetValue()) + profile.putProfileSetting('nozzle_size', self.nozzleSize.GetValue()) + profile.putProfileSetting('wall_thickness', float(profile.getProfileSettingFloat('nozzle_size')) * 2) + profile.putPreference('has_heated_bed', str(self.heatedBed.GetValue())) + ++ + class MachineSelectPage(InfoPage): + def __init__(self, parent): + super(MachineSelectPage, self).__init__(parent, "Select your machine") + self.AddText('What kind of machine do you have:') + + self.UltimakerRadio = self.AddRadioButton("Ultimaker", style=wx.RB_GROUP) + self.UltimakerRadio.SetValue(True) + self.UltimakerRadio.Bind(wx.EVT_RADIOBUTTON, self.OnUltimakerSelect) + self.OtherRadio = self.AddRadioButton("Other (Ex: RepRap)") + self.OtherRadio.Bind(wx.EVT_RADIOBUTTON, self.OnOtherSelect) - ++ + def OnUltimakerSelect(self, e): + wx.wizard.WizardPageSimple.Chain(self, self.GetParent().ultimakerFirmwareUpgradePage) - ++ + def OnOtherSelect(self, e): + wx.wizard.WizardPageSimple.Chain(self, self.GetParent().repRapInfoPage) - ++ + def StoreData(self): + if self.UltimakerRadio.GetValue(): + profile.putPreference('machine_width', '205') + profile.putPreference('machine_depth', '205') + profile.putPreference('machine_height', '200') + profile.putPreference('machine_type', 'ultimaker') + profile.putProfileSetting('nozzle_size', '0.4') + else: + profile.putPreference('machine_width', '80') + profile.putPreference('machine_depth', '80') + profile.putPreference('machine_height', '60') + profile.putPreference('machine_type', 'reprap') + profile.putPreference('startMode', 'Normal') + profile.putProfileSetting('nozzle_size', '0.5') + profile.putProfileSetting('wall_thickness', float(profile.getProfileSetting('nozzle_size')) * 2) + ++ + class SelectParts(InfoPage): + def __init__(self, parent): + super(SelectParts, self).__init__(parent, "Select upgraded parts you have") + self.AddText('To assist you in having better default settings for your Ultimaker\nCura would like to know which upgrades you have in your machine.') + self.AddSeperator() + self.springExtruder = self.AddCheckbox('Extruder drive upgrade') + self.heatedBed = self.AddCheckbox('Heated printer bed (self build)') + self.dualExtrusion = self.AddCheckbox('Dual extrusion (experimental)') + self.AddSeperator() + self.AddText('If you have an Ultimaker bought after october 2012 you will have the\nExtruder drive upgrade. If you do not have this upgrade,\nit is highly recommended to improve reliablity.') + self.AddText('This upgrade can be bought from the Ultimaker webshop shop\nor found on thingiverse as thing:26094') + self.springExtruder.SetValue(True) + + def StoreData(self): + profile.putPreference('ultimaker_extruder_upgrade', str(self.springExtruder.GetValue())) + profile.putPreference('has_heated_bed', str(self.heatedBed.GetValue())) + if self.dualExtrusion.GetValue(): + profile.putPreference('extruder_amount', '2') + if getPreference('ultimaker_extruder_upgrade') == 'True': + putProfileSetting('retraction_enable', 'True') + ++ + class FirmwareUpgradePage(InfoPage): + def __init__(self, parent): + super(FirmwareUpgradePage, self).__init__(parent, "Upgrade Ultimaker Firmware") - self.AddText('Firmware is the piece of software running directly on your 3D printer.\nThis firmware controls the step motors, regulates the temperature\nand ultimately makes your printer work.') ++ self.AddText( ++ 'Firmware is the piece of software running directly on your 3D printer.\nThis firmware controls the step motors, regulates the temperature\nand ultimately makes your printer work.') + self.AddHiddenSeperator() - self.AddText('The firmware shipping with new Ultimakers works, but upgrades\nhave been made to make better prints, and make calibration easier.') ++ self.AddText( ++ 'The firmware shipping with new Ultimakers works, but upgrades\nhave been made to make better prints, and make calibration easier.') + self.AddHiddenSeperator() - self.AddText('Cura requires these new features and thus\nyour firmware will most likely need to be upgraded.\nYou will get the chance to do so now.') ++ self.AddText( ++ 'Cura requires these new features and thus\nyour firmware will most likely need to be upgraded.\nYou will get the chance to do so now.') + upgradeButton, skipUpgradeButton = self.AddDualButton('Upgrade to Marlin firmware', 'Skip upgrade') + upgradeButton.Bind(wx.EVT_BUTTON, self.OnUpgradeClick) + skipUpgradeButton.Bind(wx.EVT_BUTTON, self.OnSkipClick) + self.AddHiddenSeperator() + self.AddText('Do not upgrade to this firmware if:') + self.AddText('* You have an older machine based on ATMega1280') + self.AddText('* Have other changes in the firmware') + button = self.AddButton('Goto this page for a custom firmware') + button.Bind(wx.EVT_BUTTON, self.OnUrlClick) - ++ + def AllowNext(self): + return False - ++ + def OnUpgradeClick(self, e): + if firmwareInstall.InstallFirmware(): + self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - ++ + def OnSkipClick(self, e): + self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - ++ + def OnUrlClick(self, e): + webbrowser.open('http://daid.mine.nu/~daid/marlin_build/') + ++ + class UltimakerCheckupPage(InfoPage): + def __init__(self, parent): + super(UltimakerCheckupPage, self).__init__(parent, "Ultimaker Checkup") + - self.checkBitmap = toolbarUtil.getBitmapImage('checkmark.png') - self.crossBitmap = toolbarUtil.getBitmapImage('cross.png') - self.unknownBitmap = toolbarUtil.getBitmapImage('question.png') - self.endStopNoneBitmap = toolbarUtil.getBitmapImage('endstop_none.png') - self.endStopXMinBitmap = toolbarUtil.getBitmapImage('endstop_xmin.png') - self.endStopXMaxBitmap = toolbarUtil.getBitmapImage('endstop_xmax.png') - self.endStopYMinBitmap = toolbarUtil.getBitmapImage('endstop_ymin.png') - self.endStopYMaxBitmap = toolbarUtil.getBitmapImage('endstop_ymax.png') - self.endStopZMinBitmap = toolbarUtil.getBitmapImage('endstop_zmin.png') - self.endStopZMaxBitmap = toolbarUtil.getBitmapImage('endstop_zmax.png') - - self.AddText('It is a good idea to do a few sanity checks now on your Ultimaker.\nYou can skip these if you know your machine is functional.') ++ self.checkBitmap = wx.Bitmap(getPathForImage('checkmark.png')) ++ self.crossBitmap = wx.Bitmap(getPathForImage('cross.png')) ++ self.unknownBitmap = wx.Bitmap(getPathForImage('question.png')) ++ self.endStopNoneBitmap = wx.Bitmap(getPathForImage('endstop_none.png')) ++ self.endStopXMinBitmap = wx.Bitmap(getPathForImage('endstop_xmin.png')) ++ self.endStopXMaxBitmap = wx.Bitmap(getPathForImage('endstop_xmax.png')) ++ self.endStopYMinBitmap = wx.Bitmap(getPathForImage('endstop_ymin.png')) ++ self.endStopYMaxBitmap = wx.Bitmap(getPathForImage('endstop_ymax.png')) ++ self.endStopZMinBitmap = wx.Bitmap(getPathForImage('endstop_zmin.png')) ++ self.endStopZMaxBitmap = wx.Bitmap(getPathForImage('endstop_zmax.png')) ++ ++ self.AddText( ++ 'It is a good idea to do a few sanity checks now on your Ultimaker.\nYou can skip these if you know your machine is functional.') + b1, b2 = self.AddDualButton('Run checks', 'Skip checks') + b1.Bind(wx.EVT_BUTTON, self.OnCheckClick) + b2.Bind(wx.EVT_BUTTON, self.OnSkipClick) + self.AddSeperator() + self.commState = self.AddCheckmark('Communication:', self.unknownBitmap) + self.tempState = self.AddCheckmark('Temperature:', self.unknownBitmap) + self.stopState = self.AddCheckmark('Endstops:', self.unknownBitmap) + self.AddSeperator() + self.infoBox = self.AddInfoBox() + self.machineState = self.AddText('') + self.temperatureLabel = self.AddText('') + self.errorLogButton = self.AddButton('Show error log') + self.errorLogButton.Show(False) + self.AddSeperator() + self.endstopBitmap = self.AddBitmap(self.endStopNoneBitmap) + self.comm = None + self.xMinStop = False + self.xMaxStop = False + self.yMinStop = False + self.yMaxStop = False + self.zMinStop = False + self.zMaxStop = False - ++ + self.Bind(wx.EVT_BUTTON, self.OnErrorLog, self.errorLogButton) + + def __del__(self): + if self.comm != None: + self.comm.close() - ++ + def AllowNext(self): + self.endstopBitmap.Show(False) + return False - ++ + def OnSkipClick(self, e): + self.GetParent().FindWindowById(wx.ID_FORWARD).Enable() - - def OnCheckClick(self, e = None): ++ ++ def OnCheckClick(self, e=None): + self.errorLogButton.Show(False) + if self.comm != None: + self.comm.close() + del self.comm + self.comm = None + wx.CallAfter(self.OnCheckClick) + return + self.infoBox.SetInfo('Connecting to machine.') + self.infoBox.SetBusyIndicator() + self.commState.SetBitmap(self.unknownBitmap) + self.tempState.SetBitmap(self.unknownBitmap) + self.stopState.SetBitmap(self.unknownBitmap) + self.checkupState = 0 + self.comm = machineCom.MachineCom(callbackObject=self) - ++ + def OnErrorLog(self, e): + printWindow.LogWindow('\n'.join(self.comm.getLog())) + + def mcLog(self, message): + pass + + def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp): + if not self.comm.isOperational(): + return + if self.checkupState == 0: + self.tempCheckTimeout = 20 + if temp > 70: + self.checkupState = 1 + wx.CallAfter(self.infoBox.SetInfo, 'Cooldown before temperature check.') + self.comm.sendCommand('M104 S0') + self.comm.sendCommand('M104 S0') + else: + self.startTemp = temp + self.checkupState = 2 + wx.CallAfter(self.infoBox.SetInfo, 'Checking the heater and temperature sensor.') + self.comm.sendCommand('M104 S200') + self.comm.sendCommand('M104 S200') + elif self.checkupState == 1: + if temp < 60: + self.startTemp = temp + self.checkupState = 2 + wx.CallAfter(self.infoBox.SetInfo, 'Checking the heater and temperature sensor.') + self.comm.sendCommand('M104 S200') + self.comm.sendCommand('M104 S200') + elif self.checkupState == 2: + #print "WARNING, TEMPERATURE TEST DISABLED FOR TESTING!" + if temp > self.startTemp + 40: + self.checkupState = 3 + wx.CallAfter(self.infoBox.SetAttention, 'Please make sure none of the endstops are pressed.') + wx.CallAfter(self.endstopBitmap.Show, True) + wx.CallAfter(self.Layout) + self.comm.sendCommand('M104 S0') + self.comm.sendCommand('M104 S0') + self.comm.sendCommand('M119') + wx.CallAfter(self.tempState.SetBitmap, self.checkBitmap) + else: + self.tempCheckTimeout -= 1 + if self.tempCheckTimeout < 1: + self.checkupState = -1 + wx.CallAfter(self.tempState.SetBitmap, self.crossBitmap) + wx.CallAfter(self.infoBox.SetError, 'Temperature measurement FAILED!', 'http://wiki.ultimaker.com/Cura/Temperature_measurement_problems') + self.comm.sendCommand('M104 S0') + self.comm.sendCommand('M104 S0') + wx.CallAfter(self.temperatureLabel.SetLabel, 'Head temperature: %d' % (temp)) + + def mcStateChange(self, state): + if self.comm == None: + return + if self.comm.isOperational(): + wx.CallAfter(self.commState.SetBitmap, self.checkBitmap) + wx.CallAfter(self.machineState.SetLabel, 'Communication State: %s' % (self.comm.getStateString())) + elif self.comm.isError(): + wx.CallAfter(self.commState.SetBitmap, self.crossBitmap) + wx.CallAfter(self.infoBox.SetError, 'Failed to establish connection with the printer.', 'http://wiki.ultimaker.com/Cura/Connection_problems') + wx.CallAfter(self.endstopBitmap.Show, False) + wx.CallAfter(self.machineState.SetLabel, '%s' % (self.comm.getErrorString())) + wx.CallAfter(self.errorLogButton.Show, True) + wx.CallAfter(self.Layout) + else: + wx.CallAfter(self.machineState.SetLabel, 'Communication State: %s' % (self.comm.getStateString())) - ++ + def mcMessage(self, message): + if self.checkupState >= 3 and self.checkupState < 10 and 'x_min' in message: + for data in message.split(' '): + if ':' in data: + tag, value = data.split(':', 2) + if tag == 'x_min': + self.xMinStop = (value == 'H') + if tag == 'x_max': + self.xMaxStop = (value == 'H') + if tag == 'y_min': + self.yMinStop = (value == 'H') + if tag == 'y_max': + self.yMaxStop = (value == 'H') + if tag == 'z_min': + self.zMinStop = (value == 'H') + if tag == 'z_max': + self.zMaxStop = (value == 'H') + self.comm.sendCommand('M119') - ++ + if self.checkupState == 3: + if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: + self.checkupState = 4 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the right X endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopXMaxBitmap) + elif self.checkupState == 4: + if not self.xMinStop and self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: + self.checkupState = 5 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the left X endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopXMinBitmap) + elif self.checkupState == 5: + if self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: + self.checkupState = 6 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the front Y endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopYMinBitmap) + elif self.checkupState == 6: + if not self.xMinStop and not self.xMaxStop and self.yMinStop and not self.yMaxStop and not self.zMinStop and not self.zMaxStop: + self.checkupState = 7 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the back Y endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopYMaxBitmap) + elif self.checkupState == 7: + if not self.xMinStop and not self.xMaxStop and not self.yMinStop and self.yMaxStop and not self.zMinStop and not self.zMaxStop: + self.checkupState = 8 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the top Z endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopZMinBitmap) + elif self.checkupState == 8: + if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and self.zMinStop and not self.zMaxStop: + self.checkupState = 9 + wx.CallAfter(self.infoBox.SetAttention, 'Please press the bottom Z endstop.') + wx.CallAfter(self.endstopBitmap.SetBitmap, self.endStopZMaxBitmap) + elif self.checkupState == 9: + if not self.xMinStop and not self.xMaxStop and not self.yMinStop and not self.yMaxStop and not self.zMinStop and self.zMaxStop: + self.checkupState = 10 + self.comm.close() + wx.CallAfter(self.infoBox.SetInfo, 'Checkup finished') + wx.CallAfter(self.infoBox.SetReadyIndicator) + wx.CallAfter(self.endstopBitmap.Show, False) + wx.CallAfter(self.stopState.SetBitmap, self.checkBitmap) + wx.CallAfter(self.OnSkipClick, None) + + def mcProgress(self, lineNr): + pass - ++ + def mcZChange(self, newZ): + pass + ++ + class UltimakerCalibrationPage(InfoPage): + def __init__(self, parent): + super(UltimakerCalibrationPage, self).__init__(parent, "Ultimaker Calibration") - ++ + self.AddText("Your Ultimaker requires some calibration.") + self.AddText("This calibration is needed for a proper extrusion amount.") + self.AddSeperator() + self.AddText("The following values are needed:") + self.AddText("* Diameter of filament") + self.AddText("* Number of steps per mm of filament extrusion") + self.AddSeperator() + self.AddText("The better you have calibrated these values, the better your prints\nwill become.") + self.AddSeperator() + self.AddText("First we need the diameter of your filament:") + self.filamentDiameter = self.AddTextCtrl(profile.getProfileSetting('filament_diameter')) - self.AddText("If you do not own digital Calipers that can measure\nat least 2 digits then use 2.89mm.\nWhich is the average diameter of most filament.") ++ self.AddText( ++ "If you do not own digital Calipers that can measure\nat least 2 digits then use 2.89mm.\nWhich is the average diameter of most filament.") + self.AddText("Note: This value can be changed later at any time.") + + def StoreData(self): + profile.putProfileSetting('filament_diameter', self.filamentDiameter.GetValue()) + ++ + class UltimakerCalibrateStepsPerEPage(InfoPage): + def __init__(self, parent): + super(UltimakerCalibrateStepsPerEPage, self).__init__(parent, "Ultimaker Calibration") + + if profile.getPreference('steps_per_e') == '0': + profile.putPreference('steps_per_e', '865.888') - ++ + self.AddText("Calibrating the Steps Per E requires some manual actions.") + self.AddText("First remove any filament from your machine.") + self.AddText("Next put in your filament so the tip is aligned with the\ntop of the extruder drive.") + self.AddText("We'll push the filament 100mm") + self.extrudeButton = self.AddButton("Extrude 100mm filament") + self.AddText("Now measure the amount of extruded filament:\n(this can be more or less then 100mm)") + self.lengthInput, self.saveLengthButton = self.AddTextCtrlButton('100', 'Save') + self.AddText("This results in the following steps per E:") + self.stepsPerEInput = self.AddTextCtrl(profile.getPreference('steps_per_e')) + self.AddText("You can repeat these steps to get better calibration.") + self.AddSeperator() - self.AddText("If you still have filament in your printer which needs\nheat to remove, press the heat up button below:") ++ self.AddText( ++ "If you still have filament in your printer which needs\nheat to remove, press the heat up button below:") + self.heatButton = self.AddButton("Heatup for filament removal") - ++ + self.saveLengthButton.Bind(wx.EVT_BUTTON, self.OnSaveLengthClick) + self.extrudeButton.Bind(wx.EVT_BUTTON, self.OnExtrudeClick) + self.heatButton.Bind(wx.EVT_BUTTON, self.OnHeatClick) - ++ + def OnSaveLengthClick(self, e): + currentEValue = float(self.stepsPerEInput.GetValue()) + realExtrudeLength = float(self.lengthInput.GetValue()) + newEValue = currentEValue * 100 / realExtrudeLength + self.stepsPerEInput.SetValue(str(newEValue)) + self.lengthInput.SetValue("100") - ++ + def OnExtrudeClick(self, e): + threading.Thread(target=self.OnExtrudeRun).start() + + def OnExtrudeRun(self): + self.heatButton.Enable(False) + self.extrudeButton.Enable(False) + currentEValue = float(self.stepsPerEInput.GetValue()) + self.comm = machineCom.MachineCom() + if not self.comm.isOpen(): - wx.MessageBox("Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", 'Printer error', wx.OK | wx.ICON_INFORMATION) ++ wx.MessageBox( ++ "Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", ++ 'Printer error', wx.OK | wx.ICON_INFORMATION) + self.heatButton.Enable(True) + self.extrudeButton.Enable(True) + return + while True: + line = self.comm.readline() + if line == '': + return + if 'start' in line: + break - #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. ++ #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. + time.sleep(3) - ++ + self.sendGCommand('M302') #Disable cold extrusion protection + self.sendGCommand("M92 E%f" % (currentEValue)) + self.sendGCommand("G92 E0") + self.sendGCommand("G1 E100 F600") + time.sleep(15) + self.comm.close() + self.extrudeButton.Enable() + self.heatButton.Enable() + + def OnHeatClick(self, e): + threading.Thread(target=self.OnHeatRun).start() - ++ + def OnHeatRun(self): + self.heatButton.Enable(False) + self.extrudeButton.Enable(False) + self.comm = machineCom.MachineCom() + if not self.comm.isOpen(): - wx.MessageBox("Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", 'Printer error', wx.OK | wx.ICON_INFORMATION) ++ wx.MessageBox( ++ "Error: Failed to open serial port to machine\nIf this keeps happening, try disconnecting and reconnecting the USB cable", ++ 'Printer error', wx.OK | wx.ICON_INFORMATION) + self.heatButton.Enable(True) + self.extrudeButton.Enable(True) + return + while True: + line = self.comm.readline() + if line == '': + self.heatButton.Enable(True) + self.extrudeButton.Enable(True) + return + if 'start' in line: + break - #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. ++ #Wait 3 seconds for the SD card init to timeout if we have SD in our firmware but there is no SD card found. + time.sleep(3) - ++ + self.sendGCommand('M104 S200') #Set the temperature to 200C, should be enough to get PLA and ABS out. - wx.MessageBox('Wait till you can remove the filament from the machine, and press OK.\n(Temperature is set to 200C)', 'Machine heatup', wx.OK | wx.ICON_INFORMATION) ++ wx.MessageBox( ++ 'Wait till you can remove the filament from the machine, and press OK.\n(Temperature is set to 200C)', ++ 'Machine heatup', wx.OK | wx.ICON_INFORMATION) + self.sendGCommand('M104 S0') + time.sleep(1) + self.comm.close() + self.heatButton.Enable(True) + self.extrudeButton.Enable(True) - ++ + def sendGCommand(self, cmd): + self.comm.sendCommand(cmd) #Disable cold extrusion protection + while True: + line = self.comm.readline() + if line == '': + return + if line.startswith('ok'): + break - ++ + def StoreData(self): + profile.putPreference('steps_per_e', self.stepsPerEInput.GetValue()) + ++ + class configWizard(wx.wizard.Wizard): + def __init__(self): + super(configWizard, self).__init__(None, -1, "Configuration Wizard") - ++ + self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGED, self.OnPageChanged) + self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging) + + self.firstInfoPage = FirstInfoPage(self) + self.machineSelectPage = MachineSelectPage(self) + self.ultimakerSelectParts = SelectParts(self) + self.ultimakerFirmwareUpgradePage = FirmwareUpgradePage(self) + self.ultimakerCheckupPage = UltimakerCheckupPage(self) + self.ultimakerCalibrationPage = UltimakerCalibrationPage(self) + self.ultimakerCalibrateStepsPerEPage = UltimakerCalibrateStepsPerEPage(self) + self.repRapInfoPage = RepRapInfoPage(self) + + wx.wizard.WizardPageSimple.Chain(self.firstInfoPage, self.machineSelectPage) + wx.wizard.WizardPageSimple.Chain(self.machineSelectPage, self.ultimakerSelectParts) + wx.wizard.WizardPageSimple.Chain(self.ultimakerSelectParts, self.ultimakerFirmwareUpgradePage) + wx.wizard.WizardPageSimple.Chain(self.ultimakerFirmwareUpgradePage, self.ultimakerCheckupPage) + #wx.wizard.WizardPageSimple.Chain(self.ultimakerCheckupPage, self.ultimakerCalibrationPage) + #wx.wizard.WizardPageSimple.Chain(self.ultimakerCalibrationPage, self.ultimakerCalibrateStepsPerEPage) - ++ + self.FitToPage(self.firstInfoPage) + self.GetPageAreaSizer().Add(self.firstInfoPage) - ++ + self.RunWizard(self.firstInfoPage) + self.Destroy() + + def OnPageChanging(self, e): + e.GetPage().StoreData() + + def OnPageChanged(self, e): + if e.GetPage().AllowNext(): - self.FindWindowById(wx.ID_FORWARD).Enable() ++ self.FindWindowById(wx.ID_FORWARD).Enable() + else: - self.FindWindowById(wx.ID_FORWARD).Disable() - self.FindWindowById(wx.ID_BACKWARD).Disable() ++ self.FindWindowById(wx.ID_FORWARD).Disable() ++ self.FindWindowById(wx.ID_BACKWARD).Disable() diff --cc Cura/gui/mainWindow.py index 48ee51d2,f20e78d4..d435194e --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@@ -110,10 -111,10 +110,10 @@@ class mainWindow(configBase.configWindo i = expertMenu.Append(-1, 'ReRun first run wizard...') self.Bind(wx.EVT_MENU, self.OnFirstRunWizard, i) menubar.Append(expertMenu, 'Expert') - + helpMenu = wx.Menu() i = helpMenu.Append(-1, 'Online documentation...') - self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://daid.github.com/Cura'), i) + self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('http://daid.github.com/Cura'), i) i = helpMenu.Append(-1, 'Report a problem...') self.Bind(wx.EVT_MENU, lambda e: webbrowser.open('https://github.com/daid/Cura/issues'), i) menubar.Append(helpMenu, 'Help') @@@ -131,10 -132,10 +131,10 @@@ #Main tabs nb = wx.Notebook(self) - + (left, right) = self.CreateConfigTab(nb, 'Print config') - + - configBase.TitleRow(left, "Accuracy") + configBase.TitleRow(left, "Quality") c = configBase.SettingRow(left, "Layer height (mm)", 'layer_height', '0.2', 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.') validators.validFloat(c, 0.0001) validators.warningAbove(c, lambda : (float(profile.getProfileSetting('nozzle_size')) * 80.0 / 100.0), "Thicker layers then %.2fmm (80%% nozzle size) usually give bad results and are not recommended.") @@@ -148,13 -149,7 +148,7 @@@ validators.validFloat(c, 0.0) c = configBase.SettingRow(left, "Fill Density (%)", 'fill_density', '20', 'This controls how densily filled the insides of your print will be. For a solid part use 100%, for an empty part use 0%. A value around 20% is usually enough') validators.validFloat(c, 0.0, 100.0) - + - configBase.TitleRow(left, "Skirt") - c = configBase.SettingRow(left, "Line count", 'skirt_line_count', '1', 'The skirt is a line drawn around the object at the first layer. This helps to prime your extruder, and to see if the object fits on your platform.\nSetting this to 0 will disable the skirt. Multiple skirt lines can help priming your extruder better for small objects.') - validators.validInt(c, 0, 10) - c = configBase.SettingRow(left, "Start distance (mm)", 'skirt_gap', '6.0', 'The distance between the skirt and the first layer.\nThis is the minimal distance, multiple skirt lines will be put outwards from this distance.') - validators.validFloat(c, 0.0) - configBase.TitleRow(right, "Speed && Temperature") c = configBase.SettingRow(right, "Print speed (mm/s)", 'print_speed', '50', 'Speed at which printing happens. A well adjusted Ultimaker can reach 150mm/s, but for good quality prints you want to print slower. Printing speed depends on a lot of factors. So you will be experimenting with optimal settings for this.') validators.validFloat(c, 1.0) @@@ -331,12 -326,8 +325,8 @@@ dlg.Destroy() if result: profile.resetGlobalProfile() - if profile.getPreference('machine_type') == 'reprap': - profile.putProfileSetting('nozzle_size', '0.5') - profile.putProfileSetting('machine_center_x', '40') - profile.putProfileSetting('machine_center_y', '40') self.updateProfileToControls() - + def OnBatchRun(self, e): br = batchRun.batchRunWindow(self) br.Centre() diff --cc Cura/gui/opengl.py index 79f3328c,9a8db81d..8e327a70 --- a/Cura/gui/opengl.py +++ b/Cura/gui/opengl.py @@@ -1,458 -1,484 +1,496 @@@ - # coding=utf-8 - from __future__ import absolute_import - - import math - - from util import meshLoader - from util import util3d - from util import profile - from util.resources import getPathForMesh - - try: - import OpenGL - - OpenGL.ERROR_CHECKING = False - from OpenGL.GLU import * - from OpenGL.GL import * - - hasOpenGLlibs = True - except: - print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/" - hasOpenGLlibs = False - - def InitGL(window, view3D, zoom): - # set viewing projection - glMatrixMode(GL_MODELVIEW) - glLoadIdentity() - size = window.GetSize() - glViewport(0, 0, size.GetWidth(), size.GetHeight()) - - glLightfv(GL_LIGHT0, GL_POSITION, [0.2, 0.2, 1.0, 0.0]) - glLightfv(GL_LIGHT1, GL_POSITION, [1.0, 1.0, 1.0, 0.0]) - - glEnable(GL_RESCALE_NORMAL) - glEnable(GL_LIGHTING) - glEnable(GL_LIGHT0) - glEnable(GL_DEPTH_TEST) - glEnable(GL_CULL_FACE) - glDisable(GL_BLEND) - - glClearColor(1.0, 1.0, 1.0, 1.0) - glClearStencil(0) - glClearDepth(1.0) - - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - aspect = float(size.GetWidth()) / float(size.GetHeight()) - if view3D: - gluPerspective(45.0, aspect, 1.0, 1000.0) - else: - glOrtho(-aspect * (zoom), aspect * (zoom), -1.0 * (zoom), 1.0 * (zoom), -1000.0, 1000.0) - - glMatrixMode(GL_MODELVIEW) - glLoadIdentity() - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) - - platformMesh = None - - def DrawMachine(machineSize): - if profile.getPreference('machine_type') == 'ultimaker': - glPushMatrix() - glEnable(GL_LIGHTING) - glTranslate(100, 200, -5) - glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8]) - glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5]) - glEnable(GL_BLEND) - glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR) - - global platformMesh - if platformMesh == None: - platformMesh = meshLoader.loadMesh(getPathForMesh('ultimaker_platform.stl')) - platformMesh.setRotateMirror(0, False, False, False, False, False) - - DrawMesh(platformMesh) - glPopMatrix() - - glDisable(GL_LIGHTING) - if False: - glColor3f(0.7, 0.7, 0.7) - glLineWidth(2) - glBegin(GL_LINES) - for i in xrange(0, int(machineSize.x), 10): - glVertex3f(i, 0, 0) - glVertex3f(i, machineSize.y, 0) - for i in xrange(0, int(machineSize.y), 10): - glVertex3f(0, i, 0) - glVertex3f(machineSize.x, i, 0) - glEnd() - - glEnable(GL_LINE_SMOOTH) - glEnable(GL_BLEND) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); - - glColor3f(0.0, 0.0, 0.0) - glLineWidth(4) - glBegin(GL_LINE_LOOP) - glVertex3f(0, 0, 0) - glVertex3f(machineSize.x, 0, 0) - glVertex3f(machineSize.x, machineSize.y, 0) - glVertex3f(0, machineSize.y, 0) - glEnd() - - glLineWidth(2) - glBegin(GL_LINE_LOOP) - glVertex3f(0, 0, machineSize.z) - glVertex3f(machineSize.x, 0, machineSize.z) - glVertex3f(machineSize.x, machineSize.y, machineSize.z) - glVertex3f(0, machineSize.y, machineSize.z) - glEnd() - glBegin(GL_LINES) - glVertex3f(0, 0, 0) - glVertex3f(0, 0, machineSize.z) - glVertex3f(machineSize.x, 0, 0) - glVertex3f(machineSize.x, 0, machineSize.z) - glVertex3f(machineSize.x, machineSize.y, 0) - glVertex3f(machineSize.x, machineSize.y, machineSize.z) - glVertex3f(0, machineSize.y, 0) - glVertex3f(0, machineSize.y, machineSize.z) - glEnd() - else: - glDisable(GL_CULL_FACE) - glEnable(GL_BLEND) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - glColor4ub(5, 171, 231, 127) - glBegin(GL_QUADS) - for x in xrange(0, int(machineSize.x), 20): - for y in xrange(0, int(machineSize.y), 20): - glVertex3f(x, y, -0.01) - glVertex3f(min(x + 10, machineSize.x), y, -0.01) - glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) - glVertex3f(x, min(y + 10, machineSize.y), -0.01) - for x in xrange(10, int(machineSize.x), 20): - for y in xrange(10, int(machineSize.y), 20): - glVertex3f(x, y, -0.01) - glVertex3f(min(x + 10, machineSize.x), y, -0.01) - glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) - glVertex3f(x, min(y + 10, machineSize.y), -0.01) - glEnd() - glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128) - glBegin(GL_QUADS) - for x in xrange(10, int(machineSize.x), 20): - for y in xrange(0, int(machineSize.y), 20): - glVertex3f(x, y, -0.01) - glVertex3f(min(x + 10, machineSize.x), y, -0.01) - glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) - glVertex3f(x, min(y + 10, machineSize.y), -0.01) - for x in xrange(0, int(machineSize.x), 20): - for y in xrange(10, int(machineSize.y), 20): - glVertex3f(x, y, -0.01) - glVertex3f(min(x + 10, machineSize.x), y, -0.01) - glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) - glVertex3f(x, min(y + 10, machineSize.y), -0.01) - glEnd() - glEnable(GL_CULL_FACE) - - glColor4ub(5, 171, 231, 64) - glBegin(GL_QUADS) - glVertex3f(0, 0, machineSize.z) - glVertex3f(0, machineSize.y, machineSize.z) - glVertex3f(machineSize.x, machineSize.y, machineSize.z) - glVertex3f(machineSize.x, 0, machineSize.z) - glEnd() - - glColor4ub(5, 171, 231, 96) - glBegin(GL_QUADS) - glVertex3f(0, 0, 0) - glVertex3f(0, 0, machineSize.z) - glVertex3f(machineSize.x, 0, machineSize.z) - glVertex3f(machineSize.x, 0, 0) - - glVertex3f(0, machineSize.y, machineSize.z) - glVertex3f(0, machineSize.y, 0) - glVertex3f(machineSize.x, machineSize.y, 0) - glVertex3f(machineSize.x, machineSize.y, machineSize.z) - glEnd() - - glColor4ub(5, 171, 231, 128) - glBegin(GL_QUADS) - glVertex3f(0, 0, machineSize.z) - glVertex3f(0, 0, 0) - glVertex3f(0, machineSize.y, 0) - glVertex3f(0, machineSize.y, machineSize.z) - - glVertex3f(machineSize.x, 0, 0) - glVertex3f(machineSize.x, 0, machineSize.z) - glVertex3f(machineSize.x, machineSize.y, machineSize.z) - glVertex3f(machineSize.x, machineSize.y, 0) - glEnd() - - glDisable(GL_BLEND) - - glPushMatrix() - glTranslate(5, 5, 2) - glLineWidth(2) - glColor3f(0.5, 0, 0) - glBegin(GL_LINES) - glVertex3f(0, 0, 0) - glVertex3f(20, 0, 0) - glEnd() - glColor3f(0, 0.5, 0) - glBegin(GL_LINES) - glVertex3f(0, 0, 0) - glVertex3f(0, 20, 0) - glEnd() - glColor3f(0, 0, 0.5) - glBegin(GL_LINES) - glVertex3f(0, 0, 0) - glVertex3f(0, 0, 20) - glEnd() - - glDisable(GL_DEPTH_TEST) - #X - glColor3f(1, 0, 0) - glPushMatrix() - glTranslate(23, 0, 0) - noZ = ResetMatrixRotationAndScale() - glBegin(GL_LINES) - glVertex3f(-0.8, 1, 0) - glVertex3f(0.8, -1, 0) - glVertex3f(0.8, 1, 0) - glVertex3f(-0.8, -1, 0) - glEnd() - glPopMatrix() - - #Y - glColor3f(0, 1, 0) - glPushMatrix() - glTranslate(0, 23, 0) - ResetMatrixRotationAndScale() - glBegin(GL_LINES) - glVertex3f(-0.8, 1, 0) - glVertex3f(0.0, 0, 0) - glVertex3f(0.8, 1, 0) - glVertex3f(-0.8, -1, 0) - glEnd() - glPopMatrix() - - #Z - if not noZ: - glColor3f(0, 0, 1) - glPushMatrix() - glTranslate(0, 0, 23) - ResetMatrixRotationAndScale() - glBegin(GL_LINES) - glVertex3f(-0.8, 1, 0) - glVertex3f(0.8, 1, 0) - glVertex3f(0.8, 1, 0) - glVertex3f(-0.8, -1, 0) - glVertex3f(-0.8, -1, 0) - glVertex3f(0.8, -1, 0) - glEnd() - glPopMatrix() - - glPopMatrix() - glEnable(GL_DEPTH_TEST) - - - def ResetMatrixRotationAndScale(): - matrix = glGetFloatv(GL_MODELVIEW_MATRIX) - noZ = False - if matrix[3][2] > 0: - return False - scale2D = matrix[0][0] - matrix[0][0] = 1.0 - matrix[1][0] = 0.0 - matrix[2][0] = 0.0 - matrix[0][1] = 0.0 - matrix[1][1] = 1.0 - matrix[2][1] = 0.0 - matrix[0][2] = 0.0 - matrix[1][2] = 0.0 - matrix[2][2] = 1.0 - - if matrix[3][2] != 0.0: - matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100) - matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100) - matrix[3][2] = -100 - else: - matrix[0][0] = scale2D - matrix[1][1] = scale2D - matrix[2][2] = scale2D - matrix[3][2] = -100 - noZ = True - - glLoadMatrixf(matrix) - return noZ - - - def DrawBox(vMin, vMax): - glBegin(GL_LINE_LOOP) - glVertex3f(vMin[0], vMin[1], vMin[2]) - glVertex3f(vMax[0], vMin[1], vMin[2]) - glVertex3f(vMax[0], vMax[1], vMin[2]) - glVertex3f(vMin[0], vMax[1], vMin[2]) - glEnd() - - glBegin(GL_LINE_LOOP) - glVertex3f(vMin[0], vMin[1], vMax[2]) - glVertex3f(vMax[0], vMin[1], vMax[2]) - glVertex3f(vMax[0], vMax[1], vMax[2]) - glVertex3f(vMin[0], vMax[1], vMax[2]) - glEnd() - glBegin(GL_LINES) - glVertex3f(vMin[0], vMin[1], vMin[2]) - glVertex3f(vMin[0], vMin[1], vMax[2]) - glVertex3f(vMax[0], vMin[1], vMin[2]) - glVertex3f(vMax[0], vMin[1], vMax[2]) - glVertex3f(vMax[0], vMax[1], vMin[2]) - glVertex3f(vMax[0], vMax[1], vMax[2]) - glVertex3f(vMin[0], vMax[1], vMin[2]) - glVertex3f(vMin[0], vMax[1], vMax[2]) - glEnd() - - - def DrawMeshOutline(mesh): - glEnable(GL_CULL_FACE) - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes) - - glCullFace(GL_FRONT) - glLineWidth(3) - glPolygonMode(GL_BACK, GL_LINE) - glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount) - glPolygonMode(GL_BACK, GL_FILL) - glCullFace(GL_BACK) - - glDisableClientState(GL_VERTEX_ARRAY) - - - def DrawMesh(mesh): - glEnable(GL_CULL_FACE) - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes) - glNormalPointer(GL_FLOAT, 0, mesh.normal) - - #Odd, drawing in batchs is a LOT faster then drawing it all at once. - batchSize = 999 #Warning, batchSize needs to be dividable by 3 - extraStartPos = int(mesh.vertexCount / batchSize) * batchSize - extraCount = mesh.vertexCount - extraStartPos - - glCullFace(GL_BACK) - for i in xrange(0, int(mesh.vertexCount / batchSize)): - glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize) - glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount) - - glCullFace(GL_FRONT) - glNormalPointer(GL_FLOAT, 0, mesh.invNormal) - for i in xrange(0, int(mesh.vertexCount / batchSize)): - glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize) - extraStartPos = int(mesh.vertexCount / batchSize) * batchSize - extraCount = mesh.vertexCount - extraStartPos - glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount) - glCullFace(GL_BACK) - - glDisableClientState(GL_VERTEX_ARRAY) - glDisableClientState(GL_NORMAL_ARRAY); - - - def DrawGCodeLayer(layer): - filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2 - filamentArea = math.pi * filamentRadius * filamentRadius - lineWidth = profile.getProfileSettingFloat('nozzle_size') / 2 / 10 - - fillCycle = 0 - fillColorCycle = [[0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]] - moveColor = [0, 0, 1] - retractColor = [1, 0, 0.5] - supportColor = [0, 1, 1] - extrudeColor = [1, 0, 0] - innerWallColor = [0, 1, 0] - skirtColor = [0, 0.5, 0.5] - prevPathWasRetract = False - - glDisable(GL_CULL_FACE) - for path in layer: - if path.type == 'move': - if prevPathWasRetract: - c = retractColor - else: - c = moveColor - zOffset = 0.01 - if path.type == 'extrude': - if path.pathType == 'FILL': - c = fillColorCycle[fillCycle] - fillCycle = (fillCycle + 1) % len(fillColorCycle) - elif path.pathType == 'WALL-INNER': - c = innerWallColor - zOffset = 0.02 - elif path.pathType == 'SUPPORT': - c = supportColor - elif path.pathType == 'SKIRT': - c = skirtColor - else: - c = extrudeColor - if path.type == 'retract': - c = [0, 1, 1] - if path.type == 'extrude': - drawLength = 0.0 - prevNormal = None - for i in xrange(0, len(path.list) - 1): - v0 = path.list[i] - v1 = path.list[i + 1] - - # Calculate line width from ePerDistance (needs layer thickness and filament diameter) - dist = (v0 - v1).vsize() - if dist > 0 and path.layerThickness > 0: - extrusionMMperDist = (v1.e - v0.e) / dist - lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply - - drawLength += (v0 - v1).vsize() - normal = (v0 - v1).cross(util3d.Vector3(0, 0, 1)) - normal.normalize() - - vv2 = v0 + normal * lineWidth - vv3 = v1 + normal * lineWidth - vv0 = v0 - normal * lineWidth - vv1 = v1 - normal * lineWidth - - glBegin(GL_QUADS) - glColor3fv(c) - glVertex3f(vv0.x, vv0.y, vv0.z - zOffset) - glVertex3f(vv1.x, vv1.y, vv1.z - zOffset) - glVertex3f(vv3.x, vv3.y, vv3.z - zOffset) - glVertex3f(vv2.x, vv2.y, vv2.z - zOffset) - glEnd() - if prevNormal != None: - n = (normal + prevNormal) - n.normalize() - vv4 = v0 + n * lineWidth - vv5 = v0 - n * lineWidth - glBegin(GL_QUADS) - glColor3fv(c) - glVertex3f(vv2.x, vv2.y, vv2.z - zOffset) - glVertex3f(vv4.x, vv4.y, vv4.z - zOffset) - glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z - zOffset) - glVertex3f(v0.x, v0.y, v0.z - zOffset) - - glVertex3f(vv0.x, vv0.y, vv0.z - zOffset) - glVertex3f(vv5.x, vv5.y, vv5.z - zOffset) - glVertex3f(prevVv1.x, prevVv1.y, prevVv1.z - zOffset) - glVertex3f(v0.x, v0.y, v0.z - zOffset) - glEnd() - - prevNormal = normal - prevVv1 = vv1 - prevVv3 = vv3 - else: - glBegin(GL_LINE_STRIP) - glColor3fv(c) - for v in path.list: - glVertex3f(v.x, v.y, v.z) - glEnd() - if not path.type == 'move': - prevPathWasRetract = False - if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]): - prevPathWasRetract = True - glEnable(GL_CULL_FACE) -import math, time, os ++# coding=utf-8 ++from __future__ import absolute_import ++ ++import math + + from util import meshLoader + from util import util3d + from util import profile ++from util.resources import getPathForMesh + + try: + import OpenGL ++ + OpenGL.ERROR_CHECKING = False + from OpenGL.GLU import * + from OpenGL.GL import * ++ + hasOpenGLlibs = True + except: + print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/" + hasOpenGLlibs = False + + def InitGL(window, view3D, zoom): + # set viewing projection + glMatrixMode(GL_MODELVIEW) + glLoadIdentity() + size = window.GetSize() - glViewport(0,0, size.GetWidth(), size.GetHeight()) - ++ glViewport(0, 0, size.GetWidth(), size.GetHeight()) ++ + glLightfv(GL_LIGHT0, GL_POSITION, [0.2, 0.2, 1.0, 0.0]) + glLightfv(GL_LIGHT1, GL_POSITION, [1.0, 1.0, 1.0, 0.0]) + + glEnable(GL_RESCALE_NORMAL) + glEnable(GL_LIGHTING) + glEnable(GL_LIGHT0) + glEnable(GL_DEPTH_TEST) + glEnable(GL_CULL_FACE) + glDisable(GL_BLEND) + + glClearColor(1.0, 1.0, 1.0, 1.0) + glClearStencil(0) + glClearDepth(1.0) + + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + aspect = float(size.GetWidth()) / float(size.GetHeight()) + if view3D: + gluPerspective(45.0, aspect, 1.0, 1000.0) + else: + glOrtho(-aspect * (zoom), aspect * (zoom), -1.0 * (zoom), 1.0 * (zoom), -1000.0, 1000.0) + + glMatrixMode(GL_MODELVIEW) + glLoadIdentity() + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) + + platformMesh = None + + def DrawMachine(machineSize): + if profile.getPreference('machine_type') == 'ultimaker': + glPushMatrix() + glEnable(GL_LIGHTING) - glTranslate(100,200,-5) - glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8,0.8,0.8]) - glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5,0.5,0.5]) ++ glTranslate(100, 200, -5) ++ glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8]) ++ glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5, 0.5, 0.5]) + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR) - ++ + global platformMesh + if platformMesh == None: - platformMesh = meshLoader.loadMesh(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", 'ultimaker_platform.stl'))) ++ platformMesh = meshLoader.loadMesh(getPathForMesh('ultimaker_platform.stl')) + platformMesh.setRotateMirror(0, False, False, False, False, False) - ++ + DrawMesh(platformMesh) + glPopMatrix() + + glDisable(GL_LIGHTING) + if False: - glColor3f(0.7,0.7,0.7) ++ glColor3f(0.7, 0.7, 0.7) + glLineWidth(2) + glBegin(GL_LINES) + for i in xrange(0, int(machineSize.x), 10): + glVertex3f(i, 0, 0) + glVertex3f(i, machineSize.y, 0) + for i in xrange(0, int(machineSize.y), 10): + glVertex3f(0, i, 0) + glVertex3f(machineSize.x, i, 0) + glEnd() - ++ + glEnable(GL_LINE_SMOOTH) + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); + - glColor3f(0.0,0.0,0.0) ++ glColor3f(0.0, 0.0, 0.0) + glLineWidth(4) + glBegin(GL_LINE_LOOP) + glVertex3f(0, 0, 0) + glVertex3f(machineSize.x, 0, 0) + glVertex3f(machineSize.x, machineSize.y, 0) + glVertex3f(0, machineSize.y, 0) + glEnd() - ++ + glLineWidth(2) + glBegin(GL_LINE_LOOP) + glVertex3f(0, 0, machineSize.z) + glVertex3f(machineSize.x, 0, machineSize.z) + glVertex3f(machineSize.x, machineSize.y, machineSize.z) + glVertex3f(0, machineSize.y, machineSize.z) + glEnd() + glBegin(GL_LINES) + glVertex3f(0, 0, 0) + glVertex3f(0, 0, machineSize.z) + glVertex3f(machineSize.x, 0, 0) + glVertex3f(machineSize.x, 0, machineSize.z) + glVertex3f(machineSize.x, machineSize.y, 0) + glVertex3f(machineSize.x, machineSize.y, machineSize.z) + glVertex3f(0, machineSize.y, 0) + glVertex3f(0, machineSize.y, machineSize.z) + glEnd() + else: + glDisable(GL_CULL_FACE) + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) - glColor4ub(5,171,231,127) ++ glColor4ub(5, 171, 231, 127) + glBegin(GL_QUADS) + for x in xrange(0, int(machineSize.x), 20): + for y in xrange(0, int(machineSize.y), 20): + glVertex3f(x, y, -0.01) - glVertex3f(min(x+10, machineSize.x), y, -0.01) - glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01) - glVertex3f(x, min(y+10, machineSize.y), -0.01) ++ glVertex3f(min(x + 10, machineSize.x), y, -0.01) ++ glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) ++ glVertex3f(x, min(y + 10, machineSize.y), -0.01) + for x in xrange(10, int(machineSize.x), 20): + for y in xrange(10, int(machineSize.y), 20): + glVertex3f(x, y, -0.01) - glVertex3f(min(x+10, machineSize.x), y, -0.01) - glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01) - glVertex3f(x, min(y+10, machineSize.y), -0.01) ++ glVertex3f(min(x + 10, machineSize.x), y, -0.01) ++ glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) ++ glVertex3f(x, min(y + 10, machineSize.y), -0.01) + glEnd() - glColor4ub(5*8/10,171*8/10,231*8/10,128) ++ glColor4ub(5 * 8 / 10, 171 * 8 / 10, 231 * 8 / 10, 128) + glBegin(GL_QUADS) + for x in xrange(10, int(machineSize.x), 20): + for y in xrange(0, int(machineSize.y), 20): + glVertex3f(x, y, -0.01) - glVertex3f(min(x+10, machineSize.x), y, -0.01) - glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01) - glVertex3f(x, min(y+10, machineSize.y), -0.01) ++ glVertex3f(min(x + 10, machineSize.x), y, -0.01) ++ glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) ++ glVertex3f(x, min(y + 10, machineSize.y), -0.01) + for x in xrange(0, int(machineSize.x), 20): + for y in xrange(10, int(machineSize.y), 20): + glVertex3f(x, y, -0.01) - glVertex3f(min(x+10, machineSize.x), y, -0.01) - glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01) - glVertex3f(x, min(y+10, machineSize.y), -0.01) ++ glVertex3f(min(x + 10, machineSize.x), y, -0.01) ++ glVertex3f(min(x + 10, machineSize.x), min(y + 10, machineSize.y), -0.01) ++ glVertex3f(x, min(y + 10, machineSize.y), -0.01) + glEnd() + glEnable(GL_CULL_FACE) + - glColor4ub(5,171,231,64) ++ glColor4ub(5, 171, 231, 64) + glBegin(GL_QUADS) + glVertex3f(0, 0, machineSize.z) + glVertex3f(0, machineSize.y, machineSize.z) + glVertex3f(machineSize.x, machineSize.y, machineSize.z) + glVertex3f(machineSize.x, 0, machineSize.z) + glEnd() - - glColor4ub(5,171,231,96) ++ ++ glColor4ub(5, 171, 231, 96) + glBegin(GL_QUADS) + glVertex3f(0, 0, 0) + glVertex3f(0, 0, machineSize.z) + glVertex3f(machineSize.x, 0, machineSize.z) + glVertex3f(machineSize.x, 0, 0) + + glVertex3f(0, machineSize.y, machineSize.z) + glVertex3f(0, machineSize.y, 0) + glVertex3f(machineSize.x, machineSize.y, 0) + glVertex3f(machineSize.x, machineSize.y, machineSize.z) + glEnd() + - glColor4ub(5,171,231,128) ++ glColor4ub(5, 171, 231, 128) + glBegin(GL_QUADS) + glVertex3f(0, 0, machineSize.z) + glVertex3f(0, 0, 0) + glVertex3f(0, machineSize.y, 0) + glVertex3f(0, machineSize.y, machineSize.z) + + glVertex3f(machineSize.x, 0, 0) + glVertex3f(machineSize.x, 0, machineSize.z) + glVertex3f(machineSize.x, machineSize.y, machineSize.z) + glVertex3f(machineSize.x, machineSize.y, 0) + glEnd() + + glDisable(GL_BLEND) - ++ + glPushMatrix() - glTranslate(5,5,2) ++ glTranslate(5, 5, 2) + glLineWidth(2) - glColor3f(0.5,0,0) ++ glColor3f(0.5, 0, 0) + glBegin(GL_LINES) - glVertex3f(0,0,0) - glVertex3f(20,0,0) ++ glVertex3f(0, 0, 0) ++ glVertex3f(20, 0, 0) + glEnd() - glColor3f(0,0.5,0) ++ glColor3f(0, 0.5, 0) + glBegin(GL_LINES) - glVertex3f(0,0,0) - glVertex3f(0,20,0) ++ glVertex3f(0, 0, 0) ++ glVertex3f(0, 20, 0) + glEnd() - glColor3f(0,0,0.5) ++ glColor3f(0, 0, 0.5) + glBegin(GL_LINES) - glVertex3f(0,0,0) - glVertex3f(0,0,20) ++ glVertex3f(0, 0, 0) ++ glVertex3f(0, 0, 20) + glEnd() + + glDisable(GL_DEPTH_TEST) + #X - glColor3f(1,0,0) ++ glColor3f(1, 0, 0) + glPushMatrix() - glTranslate(23,0,0) ++ glTranslate(23, 0, 0) + noZ = ResetMatrixRotationAndScale() + glBegin(GL_LINES) - glVertex3f(-0.8,1,0) - glVertex3f(0.8,-1,0) - glVertex3f(0.8,1,0) - glVertex3f(-0.8,-1,0) ++ glVertex3f(-0.8, 1, 0) ++ glVertex3f(0.8, -1, 0) ++ glVertex3f(0.8, 1, 0) ++ glVertex3f(-0.8, -1, 0) + glEnd() + glPopMatrix() + + #Y - glColor3f(0,1,0) ++ glColor3f(0, 1, 0) + glPushMatrix() - glTranslate(0,23,0) ++ glTranslate(0, 23, 0) + ResetMatrixRotationAndScale() + glBegin(GL_LINES) - glVertex3f(-0.8, 1,0) - glVertex3f( 0.0, 0,0) - glVertex3f( 0.8, 1,0) - glVertex3f(-0.8,-1,0) ++ glVertex3f(-0.8, 1, 0) ++ glVertex3f(0.0, 0, 0) ++ glVertex3f(0.8, 1, 0) ++ glVertex3f(-0.8, -1, 0) + glEnd() + glPopMatrix() + + #Z + if not noZ: - glColor3f(0,0,1) ++ glColor3f(0, 0, 1) + glPushMatrix() - glTranslate(0,0,23) ++ glTranslate(0, 0, 23) + ResetMatrixRotationAndScale() + glBegin(GL_LINES) - glVertex3f(-0.8, 1,0) - glVertex3f( 0.8, 1,0) - glVertex3f( 0.8, 1,0) - glVertex3f(-0.8,-1,0) - glVertex3f(-0.8,-1,0) - glVertex3f( 0.8,-1,0) ++ glVertex3f(-0.8, 1, 0) ++ glVertex3f(0.8, 1, 0) ++ glVertex3f(0.8, 1, 0) ++ glVertex3f(-0.8, -1, 0) ++ glVertex3f(-0.8, -1, 0) ++ glVertex3f(0.8, -1, 0) + glEnd() + glPopMatrix() + + glPopMatrix() + glEnable(GL_DEPTH_TEST) - ++ ++ + def ResetMatrixRotationAndScale(): + matrix = glGetFloatv(GL_MODELVIEW_MATRIX) + noZ = False + if matrix[3][2] > 0: + return False + scale2D = matrix[0][0] + matrix[0][0] = 1.0 + matrix[1][0] = 0.0 + matrix[2][0] = 0.0 + matrix[0][1] = 0.0 + matrix[1][1] = 1.0 + matrix[2][1] = 0.0 + matrix[0][2] = 0.0 + matrix[1][2] = 0.0 + matrix[2][2] = 1.0 - ++ + if matrix[3][2] != 0.0: + matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100) + matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100) + matrix[3][2] = -100 + else: + matrix[0][0] = scale2D + matrix[1][1] = scale2D + matrix[2][2] = scale2D + matrix[3][2] = -100 + noZ = True - ++ + glLoadMatrixf(matrix) + return noZ + ++ + def DrawBox(vMin, vMax): + glBegin(GL_LINE_LOOP) + glVertex3f(vMin[0], vMin[1], vMin[2]) + glVertex3f(vMax[0], vMin[1], vMin[2]) + glVertex3f(vMax[0], vMax[1], vMin[2]) + glVertex3f(vMin[0], vMax[1], vMin[2]) + glEnd() + + glBegin(GL_LINE_LOOP) + glVertex3f(vMin[0], vMin[1], vMax[2]) + glVertex3f(vMax[0], vMin[1], vMax[2]) + glVertex3f(vMax[0], vMax[1], vMax[2]) + glVertex3f(vMin[0], vMax[1], vMax[2]) + glEnd() + glBegin(GL_LINES) + glVertex3f(vMin[0], vMin[1], vMin[2]) + glVertex3f(vMin[0], vMin[1], vMax[2]) + glVertex3f(vMax[0], vMin[1], vMin[2]) + glVertex3f(vMax[0], vMin[1], vMax[2]) + glVertex3f(vMax[0], vMax[1], vMin[2]) + glVertex3f(vMax[0], vMax[1], vMax[2]) + glVertex3f(vMin[0], vMax[1], vMin[2]) + glVertex3f(vMin[0], vMax[1], vMax[2]) + glEnd() + ++ + def DrawMeshOutline(mesh): + glEnable(GL_CULL_FACE) + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes) + + glCullFace(GL_FRONT) + glLineWidth(3) + glPolygonMode(GL_BACK, GL_LINE) + glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount) + glPolygonMode(GL_BACK, GL_FILL) + glCullFace(GL_BACK) - ++ + glDisableClientState(GL_VERTEX_ARRAY) + ++ + def DrawMesh(mesh): + glEnable(GL_CULL_FACE) + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes) + glNormalPointer(GL_FLOAT, 0, mesh.normal) + + #Odd, drawing in batchs is a LOT faster then drawing it all at once. - batchSize = 999 #Warning, batchSize needs to be dividable by 3 ++ batchSize = 999 #Warning, batchSize needs to be dividable by 3 + extraStartPos = int(mesh.vertexCount / batchSize) * batchSize + extraCount = mesh.vertexCount - extraStartPos - ++ + glCullFace(GL_BACK) + for i in xrange(0, int(mesh.vertexCount / batchSize)): - glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize) ++ glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize) + glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount) - ++ + glCullFace(GL_FRONT) + glNormalPointer(GL_FLOAT, 0, mesh.invNormal) + for i in xrange(0, int(mesh.vertexCount / batchSize)): - glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize) ++ glDrawArrays(GL_TRIANGLES, i * batchSize, batchSize) + extraStartPos = int(mesh.vertexCount / batchSize) * batchSize + extraCount = mesh.vertexCount - extraStartPos + glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount) + glCullFace(GL_BACK) - ++ + glDisableClientState(GL_VERTEX_ARRAY) + glDisableClientState(GL_NORMAL_ARRAY); + ++ + def DrawMeshSteep(mesh, angle): + cosAngle = math.sin(angle / 180.0 * math.pi) + glDisable(GL_LIGHTING) + glDepthFunc(GL_EQUAL) + for i in xrange(0, int(mesh.vertexCount), 3): + if mesh.normal[i][2] < -0.999999: - if mesh.vertexes[i+0][2] > 0.01: - glColor3f(0.5,0,0) ++ if mesh.vertexes[i + 0][2] > 0.01: ++ glColor3f(0.5, 0, 0) + glBegin(GL_TRIANGLES) - glVertex3f(mesh.vertexes[i+0][0], mesh.vertexes[i+0][1], mesh.vertexes[i+0][2]) - glVertex3f(mesh.vertexes[i+1][0], mesh.vertexes[i+1][1], mesh.vertexes[i+1][2]) - glVertex3f(mesh.vertexes[i+2][0], mesh.vertexes[i+2][1], mesh.vertexes[i+2][2]) ++ glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) ++ glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) ++ glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) + glEnd() + elif mesh.normal[i][2] < -cosAngle: - glColor3f(-mesh.normal[i][2],0,0) ++ glColor3f(-mesh.normal[i][2], 0, 0) + glBegin(GL_TRIANGLES) - glVertex3f(mesh.vertexes[i+0][0], mesh.vertexes[i+0][1], mesh.vertexes[i+0][2]) - glVertex3f(mesh.vertexes[i+1][0], mesh.vertexes[i+1][1], mesh.vertexes[i+1][2]) - glVertex3f(mesh.vertexes[i+2][0], mesh.vertexes[i+2][1], mesh.vertexes[i+2][2]) ++ glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) ++ glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) ++ glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) + glEnd() + elif mesh.normal[i][2] > 0.999999: - if mesh.vertexes[i+0][2] > 0.01: - glColor3f(0.5,0,0) ++ if mesh.vertexes[i + 0][2] > 0.01: ++ glColor3f(0.5, 0, 0) + glBegin(GL_TRIANGLES) - glVertex3f(mesh.vertexes[i+0][0], mesh.vertexes[i+0][1], mesh.vertexes[i+0][2]) - glVertex3f(mesh.vertexes[i+2][0], mesh.vertexes[i+2][1], mesh.vertexes[i+2][2]) - glVertex3f(mesh.vertexes[i+1][0], mesh.vertexes[i+1][1], mesh.vertexes[i+1][2]) ++ glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) ++ glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) ++ glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) + glEnd() + elif mesh.normal[i][2] > cosAngle: - glColor3f(mesh.normal[i][2],0,0) ++ glColor3f(mesh.normal[i][2], 0, 0) + glBegin(GL_TRIANGLES) - glVertex3f(mesh.vertexes[i+0][0], mesh.vertexes[i+0][1], mesh.vertexes[i+0][2]) - glVertex3f(mesh.vertexes[i+2][0], mesh.vertexes[i+2][1], mesh.vertexes[i+2][2]) - glVertex3f(mesh.vertexes[i+1][0], mesh.vertexes[i+1][1], mesh.vertexes[i+1][2]) ++ glVertex3f(mesh.vertexes[i + 0][0], mesh.vertexes[i + 0][1], mesh.vertexes[i + 0][2]) ++ glVertex3f(mesh.vertexes[i + 2][0], mesh.vertexes[i + 2][1], mesh.vertexes[i + 2][2]) ++ glVertex3f(mesh.vertexes[i + 1][0], mesh.vertexes[i + 1][1], mesh.vertexes[i + 1][2]) + glEnd() + glDepthFunc(GL_LESS) + ++ + def DrawGCodeLayer(layer): + filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2 + filamentArea = math.pi * filamentRadius * filamentRadius + lineWidth = profile.getProfileSettingFloat('nozzle_size') / 2 / 10 - ++ + fillCycle = 0 - fillColorCycle = [[0.5,0.5,0.0],[0.0,0.5,0.5],[0.5,0.0,0.5]] - moveColor = [0,0,1] - retractColor = [1,0,0.5] - supportColor = [0,1,1] - extrudeColor = [1,0,0] - innerWallColor = [0,1,0] - skirtColor = [0,0.5,0.5] ++ fillColorCycle = [[0.5, 0.5, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]] ++ moveColor = [0, 0, 1] ++ retractColor = [1, 0, 0.5] ++ supportColor = [0, 1, 1] ++ extrudeColor = [1, 0, 0] ++ innerWallColor = [0, 1, 0] ++ skirtColor = [0, 0.5, 0.5] + prevPathWasRetract = False - ++ + glDisable(GL_CULL_FACE) + for path in layer: + if path.type == 'move': + if prevPathWasRetract: + c = retractColor + else: + c = moveColor + zOffset = 0.01 + if path.type == 'extrude': + if path.pathType == 'FILL': + c = fillColorCycle[fillCycle] + fillCycle = (fillCycle + 1) % len(fillColorCycle) + elif path.pathType == 'WALL-INNER': + c = innerWallColor + zOffset = 0.02 + elif path.pathType == 'SUPPORT': + c = supportColor + elif path.pathType == 'SKIRT': + c = skirtColor + else: + c = extrudeColor + if path.type == 'retract': - c = [0,1,1] ++ c = [0, 1, 1] + if path.type == 'extrude': + drawLength = 0.0 + prevNormal = None - for i in xrange(0, len(path.list)-1): ++ for i in xrange(0, len(path.list) - 1): + v0 = path.list[i] - v1 = path.list[i+1] ++ v1 = path.list[i + 1] + + # Calculate line width from ePerDistance (needs layer thickness and filament diameter) + dist = (v0 - v1).vsize() + if dist > 0 and path.layerThickness > 0: + extrusionMMperDist = (v1.e - v0.e) / dist + lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply + + drawLength += (v0 - v1).vsize() - normal = (v0 - v1).cross(util3d.Vector3(0,0,1)) ++ normal = (v0 - v1).cross(util3d.Vector3(0, 0, 1)) + normal.normalize() + + vv2 = v0 + normal * lineWidth + vv3 = v1 + normal * lineWidth + vv0 = v0 - normal * lineWidth + vv1 = v1 - normal * lineWidth + + glBegin(GL_QUADS) + glColor3fv(c) + glVertex3f(vv0.x, vv0.y, vv0.z - zOffset) + glVertex3f(vv1.x, vv1.y, vv1.z - zOffset) + glVertex3f(vv3.x, vv3.y, vv3.z - zOffset) + glVertex3f(vv2.x, vv2.y, vv2.z - zOffset) + glEnd() + if prevNormal != None: + n = (normal + prevNormal) + n.normalize() + vv4 = v0 + n * lineWidth + vv5 = v0 - n * lineWidth + glBegin(GL_QUADS) + glColor3fv(c) + glVertex3f(vv2.x, vv2.y, vv2.z - zOffset) + glVertex3f(vv4.x, vv4.y, vv4.z - zOffset) + glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z - zOffset) + glVertex3f(v0.x, v0.y, v0.z - zOffset) - ++ + glVertex3f(vv0.x, vv0.y, vv0.z - zOffset) + glVertex3f(vv5.x, vv5.y, vv5.z - zOffset) + glVertex3f(prevVv1.x, prevVv1.y, prevVv1.z - zOffset) + glVertex3f(v0.x, v0.y, v0.z - zOffset) + glEnd() - ++ + prevNormal = normal + prevVv1 = vv1 + prevVv3 = vv3 + else: + glBegin(GL_LINE_STRIP) + glColor3fv(c) + for v in path.list: + glVertex3f(v.x, v.y, v.z) + glEnd() + if not path.type == 'move': + prevPathWasRetract = False + if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]): + prevPathWasRetract = True + glEnable(GL_CULL_FACE) diff --cc Cura/gui/printWindow.py index 87d898be,e2cf43dd..145fd7c9 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@@ -55,681 -45,670 +55,688 @@@ class printProcessMonitor() if platform.machine() == 'i386': cmdList.insert(0, 'arch') cmdList.insert(1, '-i386') - self.handle = subprocess.Popen(cmdList, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - self.thread = threading.Thread(target=self.Monitor) - self.thread.start() - else: - self.handle.stdin.write(filename + '\n') - - def Monitor(self): - p = self.handle - line = p.stdout.readline() - while(len(line) > 0): - #print line.rstrip() - line = p.stdout.readline() - p.communicate() - self.handle = None - self.thread = None - -class PrintCommandButton(buttons.GenBitmapButton): - def __init__(self, parent, commandList, bitmapFilename, size=(20,20)): - self.bitmap = toolbarUtil.getBitmapImage(bitmapFilename) - super(PrintCommandButton, self).__init__(parent.directControlPanel, -1, self.bitmap, size=size) - - self.commandList = commandList - self.parent = parent - - self.SetBezelWidth(1) - self.SetUseFocusIndicator(False) - - self.Bind(wx.EVT_BUTTON, self.OnClick) - - def OnClick(self, e): - if self.parent.machineCom == None or self.parent.machineCom.isPrinting(): - return; - for cmd in self.commandList: - self.parent.machineCom.sendCommand(cmd) - e.Skip() - -class printWindow(wx.Frame): - "Main user interface window" - def __init__(self): - super(printWindow, self).__init__(None, -1, title='Printing') - self.machineCom = None - self.gcode = None - self.gcodeList = None - self.sendList = [] - self.temp = None - self.bedTemp = None - self.bufferLineCount = 4 - self.sendCnt = 0 - self.feedrateRatioOuterWall = 1.0 - self.feedrateRatioInnerWall = 1.0 - self.feedrateRatioFill = 1.0 - self.feedrateRatioSupport = 1.0 - self.pause = False - self.termHistory = [] - self.termHistoryIdx = 0 - - self.cam = None - if webcam.hasWebcamSupport(): - self.cam = webcam.webcam() - if not self.cam.hasCamera(): - self.cam = None - - #self.SetIcon(icon.getMainIcon()) - - self.SetSizer(wx.BoxSizer()) - self.panel = wx.Panel(self) - self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND) - self.sizer = wx.GridBagSizer(2, 2) - self.panel.SetSizer(self.sizer) - - sb = wx.StaticBox(self.panel, label="Statistics") - boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL) - - self.powerWarningText = wx.StaticText(parent=self.panel, - id=-1, - label="Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish.", - style=wx.ALIGN_CENTER) - self.powerWarningText.SetBackgroundColour('red') - self.powerWarningText.SetForegroundColour('white') - boxsizer.AddF(self.powerWarningText, flags=wx.SizerFlags().Expand().Border(wx.BOTTOM, 10)) - self.powerManagement = power.PowerManagement() - self.powerWarningTimer = wx.Timer(self) - self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer) - self.OnPowerWarningChange(None) - self.powerWarningTimer.Start(10000) - - self.statsText = wx.StaticText(self.panel, -1, "Filament: ####.##m #.##g\nEstimated print time: #####:##\nMachine state:\nDetecting baudrateXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") - boxsizer.Add(self.statsText, flag=wx.LEFT, border=5) - - self.sizer.Add(boxsizer, pos=(0,0), span=(7,1), flag=wx.EXPAND) - - self.connectButton = wx.Button(self.panel, -1, 'Connect') - #self.loadButton = wx.Button(self.panel, -1, 'Load') - self.printButton = wx.Button(self.panel, -1, 'Print') - self.pauseButton = wx.Button(self.panel, -1, 'Pause') - self.cancelButton = wx.Button(self.panel, -1, 'Cancel print') - self.machineLogButton = wx.Button(self.panel, -1, 'Error log') - self.progress = wx.Gauge(self.panel, -1) - - self.sizer.Add(self.connectButton, pos=(1,1), flag=wx.EXPAND) - #self.sizer.Add(self.loadButton, pos=(1,1), flag=wx.EXPAND) - self.sizer.Add(self.printButton, pos=(2,1), flag=wx.EXPAND) - self.sizer.Add(self.pauseButton, pos=(3,1), flag=wx.EXPAND) - self.sizer.Add(self.cancelButton, pos=(4,1), flag=wx.EXPAND) - self.sizer.Add(self.machineLogButton, pos=(5,1), flag=wx.EXPAND) - self.sizer.Add(self.progress, pos=(7,0), span=(1,7), flag=wx.EXPAND) - - nb = wx.Notebook(self.panel) - self.sizer.Add(nb, pos=(0,2), span=(7,4), flag=wx.EXPAND) - - self.temperaturePanel = wx.Panel(nb) - sizer = wx.GridBagSizer(2, 2) - self.temperaturePanel.SetSizer(sizer) - - self.temperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.temperatureSelect.SetRange(0, 400) - self.bedTemperatureLabel = wx.StaticText(self.temperaturePanel, -1, "BedTemp:") - self.bedTemperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.bedTemperatureSelect.SetRange(0, 400) - self.bedTemperatureLabel.Show(False) - self.bedTemperatureSelect.Show(False) - - self.temperatureGraph = temperatureGraph(self.temperaturePanel) - - sizer.Add(wx.StaticText(self.temperaturePanel, -1, "Temp:"), pos=(0,0)) - sizer.Add(self.temperatureSelect, pos=(0,1)) - sizer.Add(self.bedTemperatureLabel, pos=(1,0)) - sizer.Add(self.bedTemperatureSelect, pos=(1,1)) - sizer.Add(self.temperatureGraph, pos=(2,0), span=(1,2), flag=wx.EXPAND) - sizer.AddGrowableRow(2) - sizer.AddGrowableCol(1) - - nb.AddPage(self.temperaturePanel, 'Temp') - - self.directControlPanel = wx.Panel(nb) - - sizer = wx.GridBagSizer(2, 2) - self.directControlPanel.SetSizer(sizer) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y100 F6000', 'G90'], 'print-move-y100.png'), pos=(0,3)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y10 F6000', 'G90'], 'print-move-y10.png'), pos=(1,3)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y1 F6000', 'G90'], 'print-move-y1.png'), pos=(2,3)) - - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-1 F6000', 'G90'], 'print-move-y-1.png'), pos=(4,3)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-10 F6000', 'G90'], 'print-move-y-10.png'), pos=(5,3)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-100 F6000', 'G90'], 'print-move-y-100.png'), pos=(6,3)) - - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-100 F6000', 'G90'], 'print-move-x-100.png'), pos=(3,0)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-10 F6000', 'G90'], 'print-move-x-10.png'), pos=(3,1)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-1 F6000', 'G90'], 'print-move-x-1.png'), pos=(3,2)) - - sizer.Add(PrintCommandButton(self, ['G28 X0 Y0'], 'print-move-home.png'), pos=(3,3)) - - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X1 F6000', 'G90'], 'print-move-x1.png'), pos=(3,4)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X10 F6000', 'G90'], 'print-move-x10.png'), pos=(3,5)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 X100 F6000', 'G90'], 'print-move-x100.png'), pos=(3,6)) - - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z10 F200', 'G90'], 'print-move-z10.png'), pos=(0,8)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z1 F200', 'G90'], 'print-move-z1.png'), pos=(1,8)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z0.1 F200', 'G90'], 'print-move-z0.1.png'), pos=(2,8)) - - sizer.Add(PrintCommandButton(self, ['G28 Z0'], 'print-move-home.png'), pos=(3,8)) - - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-0.1 F200', 'G90'], 'print-move-z-0.1.png'), pos=(4,8)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-1 F200', 'G90'], 'print-move-z-1.png'), pos=(5,8)) - sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-10 F200', 'G90'], 'print-move-z-10.png'), pos=(6,8)) - - sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'], 'extrude.png', size=(60,20)), pos=(1,10), span=(1,3), flag=wx.EXPAND) - sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'], 'retract.png', size=(60,20)), pos=(2,10), span=(1,3), flag=wx.EXPAND) - - nb.AddPage(self.directControlPanel, 'Jog') - - self.speedPanel = wx.Panel(nb) - sizer = wx.GridBagSizer(2, 2) - self.speedPanel.SetSizer(sizer) - - self.outerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.outerWallSpeedSelect.SetRange(5, 1000) - self.innerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.innerWallSpeedSelect.SetRange(5, 1000) - self.fillSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.fillSpeedSelect.SetRange(5, 1000) - self.supportSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21*3,21), style=wx.SP_ARROW_KEYS) - self.supportSpeedSelect.SetRange(5, 1000) - - sizer.Add(wx.StaticText(self.speedPanel, -1, "Outer wall:"), pos=(0,0)) - sizer.Add(self.outerWallSpeedSelect, pos=(0,1)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(0,2)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "Inner wall:"), pos=(1,0)) - sizer.Add(self.innerWallSpeedSelect, pos=(1,1)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(1,2)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "Fill:"), pos=(2,0)) - sizer.Add(self.fillSpeedSelect, pos=(2,1)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(2,2)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "Support:"), pos=(3,0)) - sizer.Add(self.supportSpeedSelect, pos=(3,1)) - sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(3,2)) - - nb.AddPage(self.speedPanel, 'Speed') - - self.termPanel = wx.Panel(nb) - sizer = wx.GridBagSizer(2, 2) - self.termPanel.SetSizer(sizer) - - f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) - self.termLog = wx.TextCtrl(self.termPanel, style=wx.TE_MULTILINE|wx.TE_DONTWRAP) - self.termLog.SetFont(f) - self.termLog.SetEditable(0) - self.termInput = wx.TextCtrl(self.termPanel, style=wx.TE_PROCESS_ENTER) - self.termInput.SetFont(f) - - sizer.Add(self.termLog, pos=(0,0),flag=wx.EXPAND) - sizer.Add(self.termInput, pos=(1,0),flag=wx.EXPAND) - sizer.AddGrowableCol(0) - sizer.AddGrowableRow(0) - - nb.AddPage(self.termPanel, 'Term') - - if self.cam != None: - self.camPage = wx.Panel(nb) - sizer = wx.GridBagSizer(2, 2) - self.camPage.SetSizer(sizer) - - self.timelapsEnable = wx.CheckBox(self.camPage, -1, 'Enable timelaps movie recording') - sizer.Add(self.timelapsEnable, pos=(0,0), span=(1,2), flag=wx.EXPAND) - - pages = self.cam.propertyPages() - self.cam.buttons = [self.timelapsEnable] - for page in pages: - button = wx.Button(self.camPage, -1, page) - button.index = pages.index(page) - sizer.Add(button, pos=(1, pages.index(page))) - button.Bind(wx.EVT_BUTTON, self.OnPropertyPageButton) - self.cam.buttons.append(button) - - self.campreviewEnable = wx.CheckBox(self.camPage, -1, 'Show preview') - sizer.Add(self.campreviewEnable, pos=(2,0), span=(1,2), flag=wx.EXPAND) - - self.camPreview = wx.Panel(self.camPage) - sizer.Add(self.camPreview, pos=(3,0), span=(1,2), flag=wx.EXPAND) - - nb.AddPage(self.camPage, 'Camera') - self.camPreview.timer = wx.Timer(self) - self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer) - self.camPreview.timer.Start(500) - self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground) - - self.sizer.AddGrowableRow(6) - self.sizer.AddGrowableCol(3) - - self.Bind(wx.EVT_CLOSE, self.OnClose) - self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect) - #self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad) - self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint) - self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause) - self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel) - self.machineLogButton.Bind(wx.EVT_BUTTON, self.OnMachineLog) - - self.Bind(wx.EVT_SPINCTRL, self.OnTempChange, self.temperatureSelect) - self.Bind(wx.EVT_SPINCTRL, self.OnBedTempChange, self.bedTemperatureSelect) - - self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.outerWallSpeedSelect) - self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.innerWallSpeedSelect) - self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.fillSpeedSelect) - self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.supportSpeedSelect) - self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self.termInput) - self.termInput.Bind(wx.EVT_CHAR, self.OnTermKey) - - self.Layout() - self.Fit() - self.Centre() - - self.statsText.SetMinSize(self.statsText.GetSize()) - - self.UpdateButtonStates() - #self.UpdateProgress() - - def OnCameraTimer(self, e): - if not self.campreviewEnable.GetValue(): - return - if self.machineCom != None and self.machineCom.isPrinting(): - return - self.cam.takeNewImage() - self.camPreview.Refresh() - - def OnCameraEraseBackground(self, e): - dc = e.GetDC() - if not dc: - dc = wx.ClientDC(self) - rect = self.GetUpdateRegion().GetBox() - dc.SetClippingRect(rect) - dc.SetBackground(wx.Brush(self.camPreview.GetBackgroundColour(), wx.SOLID)) - if self.cam.getLastImage() != None: - self.camPreview.SetMinSize((self.cam.getLastImage().GetWidth(), self.cam.getLastImage().GetHeight())) - self.camPage.Fit() - dc.DrawBitmap(self.cam.getLastImage(), 0, 0) - else: - dc.Clear() - - def OnPropertyPageButton(self, e): - self.cam.openPropertyPage(e.GetEventObject().index) - - def UpdateButtonStates(self): - self.connectButton.Enable(self.machineCom == None or self.machineCom.isClosedOrError()) - #self.loadButton.Enable(self.machineCom == None or not (self.machineCom.isPrinting() or self.machineCom.isPaused())) - self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not (self.machineCom.isPrinting() or self.machineCom.isPaused())) - self.pauseButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused())) - if self.machineCom != None and self.machineCom.isPaused(): - self.pauseButton.SetLabel('Resume') - else: - self.pauseButton.SetLabel('Pause') - self.cancelButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused())) - self.temperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational()) - self.bedTemperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational()) - self.directControlPanel.Enable(self.machineCom != None and self.machineCom.isOperational() and not self.machineCom.isPrinting()) - self.machineLogButton.Show(self.machineCom != None and self.machineCom.isClosedOrError()) - if self.cam != None: - for button in self.cam.buttons: - button.Enable(self.machineCom == None or not self.machineCom.isPrinting()) - - def UpdateProgress(self): - status = "" - if self.gcode == None: - status += "Loading gcode...\n" - else: - status += "Filament: %.2fm %.2fg\n" % (self.gcode.extrusionAmount / 1000, self.gcode.calculateWeight() * 1000) - cost = self.gcode.calculateCost() - if cost != False: - status += "Filament cost: %s\n" % (cost) - status += "Estimated print time: %02d:%02d\n" % (int(self.gcode.totalMoveTimeMinute / 60), int(self.gcode.totalMoveTimeMinute % 60)) - if self.machineCom == None or not self.machineCom.isPrinting(): - self.progress.SetValue(0) - if self.gcodeList != None: - status += 'Line: -/%d\n' % (len(self.gcodeList)) - else: - printTime = self.machineCom.getPrintTime() / 60 - printTimeLeft = self.machineCom.getPrintTimeRemainingEstimate() - status += 'Line: %d/%d %d%%\n' % (self.machineCom.getPrintPos(), len(self.gcodeList), self.machineCom.getPrintPos() * 100 / len(self.gcodeList)) - if self.currentZ > 0: - status += 'Height: %0.1f\n' % (self.currentZ) - status += 'Print time: %02d:%02d\n' % (int(printTime / 60), int(printTime % 60)) - if printTimeLeft == None: - status += 'Print time left: Unknown\n' - else: - status += 'Print time left: %02d:%02d\n' % (int(printTimeLeft / 60), int(printTimeLeft % 60)) - self.progress.SetValue(self.machineCom.getPrintPos()) - taskbar.setProgress(self, self.machineCom.getPrintPos(), len(self.gcodeList)) - if self.machineCom != None: - if self.machineCom.getTemp() > 0: - status += 'Temp: %d\n' % (self.machineCom.getTemp()) - if self.machineCom.getBedTemp() > 0: - status += 'Bed Temp: %d\n' % (self.machineCom.getBedTemp()) - self.bedTemperatureLabel.Show(True) - self.bedTemperatureSelect.Show(True) - self.temperaturePanel.Layout() - status += 'Machine state:%s\n' % (self.machineCom.getStateString()) - - self.statsText.SetLabel(status.strip()) - - def OnConnect(self, e): - if self.machineCom != None: - self.machineCom.close() - self.machineCom = machineCom.MachineCom(callbackObject=self) - self.UpdateButtonStates() - taskbar.setBusy(self, True) - - def OnLoad(self, e): - pass - - def OnPrint(self, e): - if self.machineCom == None or not self.machineCom.isOperational(): - return - if self.gcodeList == None: - return - if self.machineCom.isPrinting(): - return - self.currentZ = -1 - if self.cam != None and self.timelapsEnable.GetValue(): - self.cam.startTimelaps(self.filename[: self.filename.rfind('.')] + ".mpg") - self.machineCom.printGCode(self.gcodeList) - self.UpdateButtonStates() - - def OnCancel(self, e): - self.pauseButton.SetLabel('Pause') - self.machineCom.cancelPrint() - self.machineCom.sendCommand("M84") - self.UpdateButtonStates() - - def OnPause(self, e): - if self.machineCom.isPaused(): - self.machineCom.setPause(False) - else: - self.machineCom.setPause(True) - - def OnMachineLog(self, e): - LogWindow('\n'.join(self.machineCom.getLog())) - - def OnClose(self, e): - global printWindowHandle - printWindowHandle = None - if self.machineCom != None: - self.machineCom.close() - self.Destroy() - - def OnTempChange(self, e): - self.machineCom.sendCommand("M104 S%d" % (self.temperatureSelect.GetValue())) - - def OnBedTempChange(self, e): - self.machineCom.sendCommand("M140 S%d" % (self.bedTemperatureSelect.GetValue())) - - def OnSpeedChange(self, e): - if self.machineCom == None: - return - self.machineCom.setFeedrateModifier('WALL-OUTER', self.outerWallSpeedSelect.GetValue() / 100.0) - self.machineCom.setFeedrateModifier('WALL-INNER', self.innerWallSpeedSelect.GetValue() / 100.0) - self.machineCom.setFeedrateModifier('FILL', self.fillSpeedSelect.GetValue() / 100.0) - self.machineCom.setFeedrateModifier('SUPPORT', self.supportSpeedSelect.GetValue() / 100.0) - - def AddTermLog(self, line): - self.termLog.AppendText(unicode(line, 'utf-8', 'replace')) - l = len(self.termLog.GetValue()) - self.termLog.SetCaret(wx.Caret(self.termLog, (l, l))) - - def OnTermEnterLine(self, e): - line = self.termInput.GetValue() - if line == '': - return - self.termLog.AppendText('>%s\n' % (line)) - self.machineCom.sendCommand(line) - self.termHistory.append(line) - self.termHistoryIdx = len(self.termHistory) - self.termInput.SetValue('') - - def OnTermKey(self, e): - if len(self.termHistory) > 0: - if e.GetKeyCode() == wx.WXK_UP: - self.termHistoryIdx = self.termHistoryIdx - 1 - if self.termHistoryIdx < 0: - self.termHistoryIdx = len(self.termHistory) - 1 - self.termInput.SetValue(self.termHistory[self.termHistoryIdx]) - if e.GetKeyCode() == wx.WXK_DOWN: - self.termHistoryIdx = self.termHistoryIdx - 1 - if self.termHistoryIdx >= len(self.termHistory): - self.termHistoryIdx = 0 - self.termInput.SetValue(self.termHistory[self.termHistoryIdx]) - e.Skip() - - def OnPowerWarningChange(self, e): - type = self.powerManagement.get_providing_power_source_type() - if type == power.POWER_TYPE_AC and self.powerWarningText.IsShown(): - self.powerWarningText.Hide() - self.panel.Layout() - self.Layout() - elif type != power.POWER_TYPE_AC and not self.powerWarningText.IsShown(): - self.powerWarningText.Show() - self.panel.Layout() - self.Layout() - - def LoadGCodeFile(self, filename): - if self.machineCom != None and self.machineCom.isPrinting(): - return - #Send an initial M110 to reset the line counter to zero. - prevLineType = lineType = 'CUSTOM' - gcodeList = ["M110"] - for line in open(filename, 'r'): - if line.startswith(';TYPE:'): - lineType = line[6:].strip() - if ';' in line: - line = line[0:line.find(';')] - line = line.strip() - if len(line) > 0: - if prevLineType != lineType: - gcodeList.append((line, lineType, )) - else: - gcodeList.append(line) - prevLineType = lineType - gcode = gcodeInterpreter.gcode() - gcode.loadList(gcodeList) - #print "Loaded: %s (%d)" % (filename, len(gcodeList)) - self.filename = filename - self.gcode = gcode - self.gcodeList = gcodeList - - wx.CallAfter(self.progress.SetRange, len(gcodeList)) - wx.CallAfter(self.UpdateButtonStates) - wx.CallAfter(self.UpdateProgress) - wx.CallAfter(self.SetTitle, 'Printing: %s' % (filename)) - - def sendLine(self, lineNr): - if lineNr >= len(self.gcodeList): - return False - line = self.gcodeList[lineNr] - try: - if ('M104' in line or 'M109' in line) and 'S' in line: - n = int(re.search('S([0-9]*)', line).group(1)) - wx.CallAfter(self.temperatureSelect.SetValue, n) - if ('M140' in line or 'M190' in line) and 'S' in line: - n = int(re.search('S([0-9]*)', line).group(1)) - wx.CallAfter(self.bedTemperatureSelect.SetValue, n) - except: - print "Unexpected error:", sys.exc_info() - checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (lineNr, line))) - self.machineCom.sendCommand("N%d%s*%d" % (lineNr, line, checksum)) - return True - - def mcLog(self, message): - #print message - pass - - def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp): - self.temperatureGraph.addPoint(temp, targetTemp, bedTemp, bedTargetTemp) - #ToFix, this causes problems with setting the temperature with the keyboard - #if self.temperatureSelect.GetValue() != targetTemp: - # wx.CallAfter(self.temperatureSelect.SetValue, targetTemp) - #if self.bedTemperatureSelect.GetValue() != bedTargetTemp: - # wx.CallAfter(self.bedTemperatureSelect.SetValue, bedTargetTemp) - - def mcStateChange(self, state): - if self.machineCom != None: - if state == self.machineCom.STATE_OPERATIONAL and self.cam != None: - self.cam.endTimelaps() - if state == self.machineCom.STATE_OPERATIONAL: - taskbar.setBusy(self, False) - if self.machineCom.isClosedOrError(): - taskbar.setBusy(self, False) - if self.machineCom.isPaused(): - taskbar.setPause(self, True) - wx.CallAfter(self.UpdateButtonStates) - wx.CallAfter(self.UpdateProgress) - - def mcMessage(self, message): - wx.CallAfter(self.AddTermLog, message) - - def mcProgress(self, lineNr): - wx.CallAfter(self.UpdateProgress) - - def mcZChange(self, newZ): - self.currentZ = newZ - if self.cam != None: - wx.CallAfter(self.cam.takeNewImage) - wx.CallAfter(self.camPreview.Refresh) - -class temperatureGraph(wx.Panel): - def __init__(self, parent): - super(temperatureGraph, self).__init__(parent) - - self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) - self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(wx.EVT_PAINT, self.OnDraw) - - self.lastDraw = time.time() - 1.0 - self.points = [] - self.backBuffer = None - self.addPoint(0,0,0,0) - self.SetMinSize((320,200)) - - def OnEraseBackground(self, e): - pass - - def OnSize(self, e): - if self.backBuffer == None or self.GetSize() != self.backBuffer.GetSize(): - self.backBuffer = wx.EmptyBitmap(*self.GetSizeTuple()) - self.UpdateDrawing(True) - - def OnDraw(self, e): - dc = wx.BufferedPaintDC(self, self.backBuffer) - - def UpdateDrawing(self, force = False): - now = time.time() - if not force and now - self.lastDraw < 1.0: - return - self.lastDraw = now - dc = wx.MemoryDC() - dc.SelectObject(self.backBuffer) - dc.Clear() - dc.SetFont(wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)) - w, h = self.GetSizeTuple() - bgLinePen = wx.Pen('#A0A0A0') - tempPen = wx.Pen('#FF4040') - tempSPPen = wx.Pen('#FFA0A0') - tempPenBG = wx.Pen('#FFD0D0') - bedTempPen = wx.Pen('#4040FF') - bedTempSPPen = wx.Pen('#A0A0FF') - bedTempPenBG = wx.Pen('#D0D0FF') - - #Draw the background up to the current temperatures. - x0 = 0 - t0 = 0 - bt0 = 0 - tSP0 = 0 - btSP0 = 0 - for temp, tempSP, bedTemp, bedTempSP, t in self.points: - x1 = int(w - (now - t)) - for x in xrange(x0, x1 + 1): - t = float(x - x0) / float(x1 - x0 + 1) * (temp - t0) + t0 - bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0 - dc.SetPen(tempPenBG) - dc.DrawLine(x, h, x, h - (t * h / 300)) - dc.SetPen(bedTempPenBG) - dc.DrawLine(x, h, x, h - (bt * h / 300)) - t0 = temp - bt0 = bedTemp - tSP0 = tempSP - btSP0 = bedTempSP - x0 = x1 + 1 - - #Draw the grid - for x in xrange(w, 0, -30): - dc.SetPen(bgLinePen) - dc.DrawLine(x, 0, x, h) - tmpNr = 0 - for y in xrange(h-1, 0, -h * 50 / 300): - dc.SetPen(bgLinePen) - dc.DrawLine(0, y, w, y) - dc.DrawText(str(tmpNr), 0, y - dc.GetFont().GetPixelSize().GetHeight()) - tmpNr += 50 - dc.DrawLine(0, 0, w, 0) - dc.DrawLine(0, 0, 0, h) - - #Draw the main lines - x0 = 0 - t0 = 0 - bt0 = 0 - tSP0 = 0 - btSP0 = 0 - for temp, tempSP, bedTemp, bedTempSP, t in self.points: - x1 = int(w - (now - t)) - for x in xrange(x0, x1 + 1): - t = float(x - x0) / float(x1 - x0 + 1) * (temp - t0) + t0 - bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0 - tSP = float(x - x0) / float(x1 - x0 + 1) * (tempSP - tSP0) + tSP0 - btSP = float(x - x0) / float(x1 - x0 + 1) * (bedTempSP - btSP0) + btSP0 - dc.SetPen(tempSPPen) - dc.DrawPoint(x, h - (tSP * h / 300)) - dc.SetPen(bedTempSPPen) - dc.DrawPoint(x, h - (btSP * h / 300)) - dc.SetPen(tempPen) - dc.DrawPoint(x, h - (t * h / 300)) - dc.SetPen(bedTempPen) - dc.DrawPoint(x, h - (bt * h / 300)) - t0 = temp - bt0 = bedTemp - tSP0 = tempSP - btSP0 = bedTempSP - x0 = x1 + 1 - - del dc - self.Refresh(eraseBackground=False) - self.Update() - - if len(self.points) > 0 and (time.time() - self.points[0][4]) > w + 20: - self.points.pop(0) - - def addPoint(self, temp, tempSP, bedTemp, bedTempSP): - if bedTemp == None: - bedTemp = 0 - if bedTempSP == None: - bedTempSP = 0 - self.points.append((temp, tempSP, bedTemp, bedTempSP, time.time())) - wx.CallAfter(self.UpdateDrawing) - -class LogWindow(wx.Frame): - def __init__(self, logText): - super(LogWindow, self).__init__(None, title="Machine log") - self.textBox = wx.TextCtrl(self, -1, logText, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_READONLY) - self.SetSize((500,400)) - self.Centre() - self.Show(True) + self.handle = subprocess.Popen(cmdList, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + self.thread = threading.Thread(target=self.Monitor) + self.thread.start() + else: + self.handle.stdin.write(filename + '\n') + + def Monitor(self): + p = self.handle + line = p.stdout.readline() + while(len(line) > 0): + #print line.rstrip() + line = p.stdout.readline() + p.communicate() + self.handle = None + self.thread = None + + +class PrintCommandButton(buttons.GenBitmapButton): + def __init__(self, parent, commandList, bitmapFilename, size=(20, 20)): + self.bitmap = wx.Bitmap(getPathForImage(bitmapFilename)) + super(PrintCommandButton, self).__init__(parent.directControlPanel, -1, self.bitmap, size=size) + + self.commandList = commandList + self.parent = parent + + self.SetBezelWidth(1) + self.SetUseFocusIndicator(False) + + self.Bind(wx.EVT_BUTTON, self.OnClick) + + def OnClick(self, e): + if self.parent.machineCom == None or self.parent.machineCom.isPrinting(): + return; + for cmd in self.commandList: + self.parent.machineCom.sendCommand(cmd) + e.Skip() + + +class printWindow(wx.Frame): + "Main user interface window" + + def __init__(self): + super(printWindow, self).__init__(None, -1, title='Printing') + self.machineCom = None + self.gcode = None + self.gcodeList = None + self.sendList = [] + self.temp = None + self.bedTemp = None + self.bufferLineCount = 4 + self.sendCnt = 0 + self.feedrateRatioOuterWall = 1.0 + self.feedrateRatioInnerWall = 1.0 + self.feedrateRatioFill = 1.0 + self.feedrateRatioSupport = 1.0 + self.pause = False + self.termHistory = [] + self.termHistoryIdx = 0 + + self.cam = None + if webcam.hasWebcamSupport(): + self.cam = webcam.webcam() + if not self.cam.hasCamera(): + self.cam = None + + #self.SetIcon(icon.getMainIcon()) + + self.SetSizer(wx.BoxSizer()) + self.panel = wx.Panel(self) + self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND) + self.sizer = wx.GridBagSizer(2, 2) + self.panel.SetSizer(self.sizer) + + sb = wx.StaticBox(self.panel, label="Statistics") + boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL) + + self.powerWarningText = wx.StaticText(parent=self.panel, + id=-1, - label="Connect your computer to AC power\nIf it shuts down during printing, the product will be lost.", ++ label="Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish.", + style=wx.ALIGN_CENTER) + self.powerWarningText.SetBackgroundColour('red') + self.powerWarningText.SetForegroundColour('white') + boxsizer.AddF(self.powerWarningText, flags=wx.SizerFlags().Expand().Border(wx.BOTTOM, 10)) + self.powerManagement = power.PowerManagement() + self.powerWarningTimer = wx.Timer(self) + self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer) + self.OnPowerWarningChange(None) + self.powerWarningTimer.Start(10000) + + self.statsText = wx.StaticText(self.panel, -1, + "Filament: ####.##m #.##g\nEstimated print time: #####:##\nMachine state:\nDetecting baudrateXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + boxsizer.Add(self.statsText, flag=wx.LEFT, border=5) + + self.sizer.Add(boxsizer, pos=(0, 0), span=(7, 1), flag=wx.EXPAND) + + self.connectButton = wx.Button(self.panel, -1, 'Connect') + #self.loadButton = wx.Button(self.panel, -1, 'Load') + self.printButton = wx.Button(self.panel, -1, 'Print') + self.pauseButton = wx.Button(self.panel, -1, 'Pause') + self.cancelButton = wx.Button(self.panel, -1, 'Cancel print') + self.machineLogButton = wx.Button(self.panel, -1, 'Error log') + self.progress = wx.Gauge(self.panel, -1) + + self.sizer.Add(self.connectButton, pos=(1, 1), flag=wx.EXPAND) + #self.sizer.Add(self.loadButton, pos=(1,1), flag=wx.EXPAND) + self.sizer.Add(self.printButton, pos=(2, 1), flag=wx.EXPAND) + self.sizer.Add(self.pauseButton, pos=(3, 1), flag=wx.EXPAND) + self.sizer.Add(self.cancelButton, pos=(4, 1), flag=wx.EXPAND) + self.sizer.Add(self.machineLogButton, pos=(5, 1), flag=wx.EXPAND) + self.sizer.Add(self.progress, pos=(7, 0), span=(1, 7), flag=wx.EXPAND) + + nb = wx.Notebook(self.panel) + self.sizer.Add(nb, pos=(0, 2), span=(7, 4), flag=wx.EXPAND) + + self.temperaturePanel = wx.Panel(nb) + sizer = wx.GridBagSizer(2, 2) + self.temperaturePanel.SetSizer(sizer) + + self.temperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS) + self.temperatureSelect.SetRange(0, 400) + self.bedTemperatureLabel = wx.StaticText(self.temperaturePanel, -1, "BedTemp:") + self.bedTemperatureSelect = wx.SpinCtrl(self.temperaturePanel, -1, '0', size=(21 * 3, 21), + style=wx.SP_ARROW_KEYS) + self.bedTemperatureSelect.SetRange(0, 400) + self.bedTemperatureLabel.Show(False) + self.bedTemperatureSelect.Show(False) + + self.temperatureGraph = temperatureGraph(self.temperaturePanel) + + sizer.Add(wx.StaticText(self.temperaturePanel, -1, "Temp:"), pos=(0, 0)) + sizer.Add(self.temperatureSelect, pos=(0, 1)) + sizer.Add(self.bedTemperatureLabel, pos=(1, 0)) + sizer.Add(self.bedTemperatureSelect, pos=(1, 1)) + sizer.Add(self.temperatureGraph, pos=(2, 0), span=(1, 2), flag=wx.EXPAND) + sizer.AddGrowableRow(2) + sizer.AddGrowableCol(1) + + nb.AddPage(self.temperaturePanel, 'Temp') + + self.directControlPanel = wx.Panel(nb) + + sizer = wx.GridBagSizer(2, 2) + self.directControlPanel.SetSizer(sizer) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y100 F6000', 'G90'], 'print-move-y100.png'), pos=(0, 3)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y10 F6000', 'G90'], 'print-move-y10.png'), pos=(1, 3)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y1 F6000', 'G90'], 'print-move-y1.png'), pos=(2, 3)) + + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-1 F6000', 'G90'], 'print-move-y-1.png'), pos=(4, 3)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-10 F6000', 'G90'], 'print-move-y-10.png'), pos=(5, 3)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Y-100 F6000', 'G90'], 'print-move-y-100.png'), pos=(6, 3)) + + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-100 F6000', 'G90'], 'print-move-x-100.png'), pos=(3, 0)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-10 F6000', 'G90'], 'print-move-x-10.png'), pos=(3, 1)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X-1 F6000', 'G90'], 'print-move-x-1.png'), pos=(3, 2)) + + sizer.Add(PrintCommandButton(self, ['G28 X0 Y0'], 'print-move-home.png'), pos=(3, 3)) + + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X1 F6000', 'G90'], 'print-move-x1.png'), pos=(3, 4)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X10 F6000', 'G90'], 'print-move-x10.png'), pos=(3, 5)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 X100 F6000', 'G90'], 'print-move-x100.png'), pos=(3, 6)) + + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z10 F200', 'G90'], 'print-move-z10.png'), pos=(0, 8)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z1 F200', 'G90'], 'print-move-z1.png'), pos=(1, 8)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z0.1 F200', 'G90'], 'print-move-z0.1.png'), pos=(2, 8)) + + sizer.Add(PrintCommandButton(self, ['G28 Z0'], 'print-move-home.png'), pos=(3, 8)) + + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-0.1 F200', 'G90'], 'print-move-z-0.1.png'), pos=(4, 8)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-1 F200', 'G90'], 'print-move-z-1.png'), pos=(5, 8)) + sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-10 F200', 'G90'], 'print-move-z-10.png'), pos=(6, 8)) + + sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'], 'extrude.png', size=(60, 20)), pos=(1, 10), + span=(1, 3), flag=wx.EXPAND) + sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'], 'retract.png', size=(60, 20)), pos=(2, 10), + span=(1, 3), flag=wx.EXPAND) + + nb.AddPage(self.directControlPanel, 'Jog') + + self.speedPanel = wx.Panel(nb) + sizer = wx.GridBagSizer(2, 2) + self.speedPanel.SetSizer(sizer) + + self.outerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS) + self.outerWallSpeedSelect.SetRange(5, 1000) + self.innerWallSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS) + self.innerWallSpeedSelect.SetRange(5, 1000) + self.fillSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS) + self.fillSpeedSelect.SetRange(5, 1000) + self.supportSpeedSelect = wx.SpinCtrl(self.speedPanel, -1, '100', size=(21 * 3, 21), style=wx.SP_ARROW_KEYS) + self.supportSpeedSelect.SetRange(5, 1000) + + sizer.Add(wx.StaticText(self.speedPanel, -1, "Outer wall:"), pos=(0, 0)) + sizer.Add(self.outerWallSpeedSelect, pos=(0, 1)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(0, 2)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "Inner wall:"), pos=(1, 0)) + sizer.Add(self.innerWallSpeedSelect, pos=(1, 1)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(1, 2)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "Fill:"), pos=(2, 0)) + sizer.Add(self.fillSpeedSelect, pos=(2, 1)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(2, 2)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "Support:"), pos=(3, 0)) + sizer.Add(self.supportSpeedSelect, pos=(3, 1)) + sizer.Add(wx.StaticText(self.speedPanel, -1, "%"), pos=(3, 2)) + + nb.AddPage(self.speedPanel, 'Speed') + + self.termPanel = wx.Panel(nb) + sizer = wx.GridBagSizer(2, 2) + self.termPanel.SetSizer(sizer) + + f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) + self.termLog = wx.TextCtrl(self.termPanel, style=wx.TE_MULTILINE | wx.TE_DONTWRAP) + self.termLog.SetFont(f) + self.termLog.SetEditable(0) + self.termInput = wx.TextCtrl(self.termPanel, style=wx.TE_PROCESS_ENTER) + self.termInput.SetFont(f) + + sizer.Add(self.termLog, pos=(0, 0), flag=wx.EXPAND) + sizer.Add(self.termInput, pos=(1, 0), flag=wx.EXPAND) + sizer.AddGrowableCol(0) + sizer.AddGrowableRow(0) + + nb.AddPage(self.termPanel, 'Term') + + if self.cam != None: + self.camPage = wx.Panel(nb) + sizer = wx.GridBagSizer(2, 2) + self.camPage.SetSizer(sizer) + + self.timelapsEnable = wx.CheckBox(self.camPage, -1, 'Enable timelaps movie recording') + sizer.Add(self.timelapsEnable, pos=(0, 0), span=(1, 2), flag=wx.EXPAND) + + pages = self.cam.propertyPages() + self.cam.buttons = [self.timelapsEnable] + for page in pages: + button = wx.Button(self.camPage, -1, page) + button.index = pages.index(page) + sizer.Add(button, pos=(1, pages.index(page))) + button.Bind(wx.EVT_BUTTON, self.OnPropertyPageButton) + self.cam.buttons.append(button) + + self.campreviewEnable = wx.CheckBox(self.camPage, -1, 'Show preview') + sizer.Add(self.campreviewEnable, pos=(2, 0), span=(1, 2), flag=wx.EXPAND) + + self.camPreview = wx.Panel(self.camPage) + sizer.Add(self.camPreview, pos=(3, 0), span=(1, 2), flag=wx.EXPAND) + + nb.AddPage(self.camPage, 'Camera') + self.camPreview.timer = wx.Timer(self) + self.Bind(wx.EVT_TIMER, self.OnCameraTimer, self.camPreview.timer) + self.camPreview.timer.Start(500) + self.camPreview.Bind(wx.EVT_ERASE_BACKGROUND, self.OnCameraEraseBackground) + - self.sizer.AddGrowableRow(5) ++ self.sizer.AddGrowableRow(6) + self.sizer.AddGrowableCol(3) + + self.Bind(wx.EVT_CLOSE, self.OnClose) + self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect) + #self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad) + self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint) + self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause) + self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel) + self.machineLogButton.Bind(wx.EVT_BUTTON, self.OnMachineLog) + + self.Bind(wx.EVT_SPINCTRL, self.OnTempChange, self.temperatureSelect) + self.Bind(wx.EVT_SPINCTRL, self.OnBedTempChange, self.bedTemperatureSelect) + + self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.outerWallSpeedSelect) + self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.innerWallSpeedSelect) + self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.fillSpeedSelect) + self.Bind(wx.EVT_SPINCTRL, self.OnSpeedChange, self.supportSpeedSelect) + self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self.termInput) + self.termInput.Bind(wx.EVT_CHAR, self.OnTermKey) + + self.Layout() + self.Fit() + self.Centre() + + self.statsText.SetMinSize(self.statsText.GetSize()) + + self.UpdateButtonStates() + + #self.UpdateProgress() + + def OnCameraTimer(self, e): + if not self.campreviewEnable.GetValue(): + return + if self.machineCom != None and self.machineCom.isPrinting(): + return + self.cam.takeNewImage() + self.camPreview.Refresh() + + def OnCameraEraseBackground(self, e): + dc = e.GetDC() + if not dc: + dc = wx.ClientDC(self) + rect = self.GetUpdateRegion().GetBox() + dc.SetClippingRect(rect) + dc.SetBackground(wx.Brush(self.camPreview.GetBackgroundColour(), wx.SOLID)) + if self.cam.getLastImage() != None: + self.camPreview.SetMinSize((self.cam.getLastImage().GetWidth(), self.cam.getLastImage().GetHeight())) + self.camPage.Fit() + dc.DrawBitmap(self.cam.getLastImage(), 0, 0) + else: + dc.Clear() + + def OnPropertyPageButton(self, e): + self.cam.openPropertyPage(e.GetEventObject().index) + + def UpdateButtonStates(self): + self.connectButton.Enable(self.machineCom == None or self.machineCom.isClosedOrError()) + #self.loadButton.Enable(self.machineCom == None or not (self.machineCom.isPrinting() or self.machineCom.isPaused())) + self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not ( + self.machineCom.isPrinting() or self.machineCom.isPaused())) + self.pauseButton.Enable( + self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused())) + if self.machineCom != None and self.machineCom.isPaused(): + self.pauseButton.SetLabel('Resume') + else: + self.pauseButton.SetLabel('Pause') + self.cancelButton.Enable( + self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused())) + self.temperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational()) + self.bedTemperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational()) + self.directControlPanel.Enable( + self.machineCom != None and self.machineCom.isOperational() and not self.machineCom.isPrinting()) + self.machineLogButton.Show(self.machineCom != None and self.machineCom.isClosedOrError()) + if self.cam != None: + for button in self.cam.buttons: + button.Enable(self.machineCom == None or not self.machineCom.isPrinting()) + + def UpdateProgress(self): + status = "" + if self.gcode == None: + status += "Loading gcode...\n" + else: + status += "Filament: %.2fm %.2fg\n" % ( + self.gcode.extrusionAmount / 1000, self.gcode.calculateWeight() * 1000) + cost = self.gcode.calculateCost() + if cost != False: + status += "Filament cost: %s\n" % (cost) + status += "Estimated print time: %02d:%02d\n" % ( + int(self.gcode.totalMoveTimeMinute / 60), int(self.gcode.totalMoveTimeMinute % 60)) + if self.machineCom == None or not self.machineCom.isPrinting(): + self.progress.SetValue(0) + if self.gcodeList != None: + status += 'Line: -/%d\n' % (len(self.gcodeList)) + else: + printTime = self.machineCom.getPrintTime() / 60 + printTimeLeft = self.machineCom.getPrintTimeRemainingEstimate() + status += 'Line: %d/%d %d%%\n' % (self.machineCom.getPrintPos(), len(self.gcodeList), + self.machineCom.getPrintPos() * 100 / len(self.gcodeList)) + if self.currentZ > 0: + status += 'Height: %0.1f\n' % (self.currentZ) + status += 'Print time: %02d:%02d\n' % (int(printTime / 60), int(printTime % 60)) + if printTimeLeft == None: + status += 'Print time left: Unknown\n' + else: + status += 'Print time left: %02d:%02d\n' % (int(printTimeLeft / 60), int(printTimeLeft % 60)) + self.progress.SetValue(self.machineCom.getPrintPos()) + taskbar.setProgress(self, self.machineCom.getPrintPos(), len(self.gcodeList)) + if self.machineCom != None: + if self.machineCom.getTemp() > 0: + status += 'Temp: %d\n' % (self.machineCom.getTemp()) + if self.machineCom.getBedTemp() > 0: + status += 'Bed Temp: %d\n' % (self.machineCom.getBedTemp()) + self.bedTemperatureLabel.Show(True) + self.bedTemperatureSelect.Show(True) + self.temperaturePanel.Layout() + status += 'Machine state:%s\n' % (self.machineCom.getStateString()) + + self.statsText.SetLabel(status.strip()) + + def OnConnect(self, e): + if self.machineCom != None: + self.machineCom.close() + self.machineCom = machineCom.MachineCom(callbackObject=self) + self.UpdateButtonStates() + taskbar.setBusy(self, True) + + def OnLoad(self, e): + pass + + def OnPrint(self, e): + if self.machineCom == None or not self.machineCom.isOperational(): + return + if self.gcodeList == None: + return + if self.machineCom.isPrinting(): + return + self.currentZ = -1 + if self.cam != None and self.timelapsEnable.GetValue(): + self.cam.startTimelaps(self.filename[: self.filename.rfind('.')] + ".mpg") + self.machineCom.printGCode(self.gcodeList) + self.UpdateButtonStates() + + def OnCancel(self, e): + self.pauseButton.SetLabel('Pause') + self.machineCom.cancelPrint() + self.machineCom.sendCommand("M84") + self.UpdateButtonStates() + + def OnPause(self, e): + if self.machineCom.isPaused(): + self.machineCom.setPause(False) + else: + self.machineCom.setPause(True) + + def OnMachineLog(self, e): + LogWindow('\n'.join(self.machineCom.getLog())) + + def OnClose(self, e): + global printWindowHandle + printWindowHandle = None + if self.machineCom != None: + self.machineCom.close() + self.Destroy() + + def OnTempChange(self, e): + self.machineCom.sendCommand("M104 S%d" % (self.temperatureSelect.GetValue())) + + def OnBedTempChange(self, e): + self.machineCom.sendCommand("M140 S%d" % (self.bedTemperatureSelect.GetValue())) + + def OnSpeedChange(self, e): + if self.machineCom == None: + return + self.machineCom.setFeedrateModifier('WALL-OUTER', self.outerWallSpeedSelect.GetValue() / 100.0) + self.machineCom.setFeedrateModifier('WALL-INNER', self.innerWallSpeedSelect.GetValue() / 100.0) + self.machineCom.setFeedrateModifier('FILL', self.fillSpeedSelect.GetValue() / 100.0) + self.machineCom.setFeedrateModifier('SUPPORT', self.supportSpeedSelect.GetValue() / 100.0) + + def AddTermLog(self, line): + self.termLog.AppendText(unicode(line, 'utf-8', 'replace')) + l = len(self.termLog.GetValue()) + self.termLog.SetCaret(wx.Caret(self.termLog, (l, l))) + + def OnTermEnterLine(self, e): + line = self.termInput.GetValue() + if line == '': + return + self.termLog.AppendText('>%s\n' % (line)) + self.machineCom.sendCommand(line) + self.termHistory.append(line) + self.termHistoryIdx = len(self.termHistory) + self.termInput.SetValue('') + + def OnTermKey(self, e): + if len(self.termHistory) > 0: + if e.GetKeyCode() == wx.WXK_UP: + self.termHistoryIdx = self.termHistoryIdx - 1 + if self.termHistoryIdx < 0: + self.termHistoryIdx = len(self.termHistory) - 1 + self.termInput.SetValue(self.termHistory[self.termHistoryIdx]) + if e.GetKeyCode() == wx.WXK_DOWN: + self.termHistoryIdx = self.termHistoryIdx - 1 + if self.termHistoryIdx >= len(self.termHistory): + self.termHistoryIdx = 0 + self.termInput.SetValue(self.termHistory[self.termHistoryIdx]) + e.Skip() + + def OnPowerWarningChange(self, e): + type = self.powerManagement.get_providing_power_source_type() + if type == power.POWER_TYPE_AC and self.powerWarningText.IsShown(): + self.powerWarningText.Hide() ++ self.panel.Layout() + self.Layout() + elif type != power.POWER_TYPE_AC and not self.powerWarningText.IsShown(): + self.powerWarningText.Show() ++ self.panel.Layout() + self.Layout() + + def LoadGCodeFile(self, filename): + if self.machineCom != None and self.machineCom.isPrinting(): + return + #Send an initial M110 to reset the line counter to zero. + prevLineType = lineType = 'CUSTOM' + gcodeList = ["M110"] + for line in open(filename, 'r'): + if line.startswith(';TYPE:'): + lineType = line[6:].strip() + if ';' in line: + line = line[0:line.find(';')] + line = line.strip() + if len(line) > 0: + if prevLineType != lineType: + gcodeList.append((line, lineType, )) + else: + gcodeList.append(line) + prevLineType = lineType + gcode = gcodeInterpreter.gcode() + gcode.loadList(gcodeList) + #print "Loaded: %s (%d)" % (filename, len(gcodeList)) + self.filename = filename + self.gcode = gcode + self.gcodeList = gcodeList + + wx.CallAfter(self.progress.SetRange, len(gcodeList)) + wx.CallAfter(self.UpdateButtonStates) + wx.CallAfter(self.UpdateProgress) + wx.CallAfter(self.SetTitle, 'Printing: %s' % (filename)) + + def sendLine(self, lineNr): + if lineNr >= len(self.gcodeList): + return False + line = self.gcodeList[lineNr] + try: + if ('M104' in line or 'M109' in line) and 'S' in line: + n = int(re.search('S([0-9]*)', line).group(1)) + wx.CallAfter(self.temperatureSelect.SetValue, n) + if ('M140' in line or 'M190' in line) and 'S' in line: + n = int(re.search('S([0-9]*)', line).group(1)) + wx.CallAfter(self.bedTemperatureSelect.SetValue, n) + except: + print "Unexpected error:", sys.exc_info() + checksum = reduce(lambda x, y: x ^ y, map(ord, "N%d%s" % (lineNr, line))) + self.machineCom.sendCommand("N%d%s*%d" % (lineNr, line, checksum)) + return True + + def mcLog(self, message): + #print message + pass + + def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp): + self.temperatureGraph.addPoint(temp, targetTemp, bedTemp, bedTargetTemp) - if self.temperatureSelect.GetValue() != targetTemp: - wx.CallAfter(self.temperatureSelect.SetValue, targetTemp) - if self.bedTemperatureSelect.GetValue() != bedTargetTemp: - wx.CallAfter(self.bedTemperatureSelect.SetValue, bedTargetTemp) ++# ToFix, this causes problems with setting the temperature with the keyboard ++# if self.temperatureSelect.GetValue() != targetTemp: ++# wx.CallAfter(self.temperatureSelect.SetValue, targetTemp) ++# if self.bedTemperatureSelect.GetValue() != bedTargetTemp: ++# wx.CallAfter(self.bedTemperatureSelect.SetValue, bedTargetTemp) + + def mcStateChange(self, state): + if self.machineCom != None: + if state == self.machineCom.STATE_OPERATIONAL and self.cam != None: + self.cam.endTimelaps() + if state == self.machineCom.STATE_OPERATIONAL: + taskbar.setBusy(self, False) + if self.machineCom.isClosedOrError(): + taskbar.setBusy(self, False) + if self.machineCom.isPaused(): + taskbar.setPause(self, True) + wx.CallAfter(self.UpdateButtonStates) + wx.CallAfter(self.UpdateProgress) + + def mcMessage(self, message): + wx.CallAfter(self.AddTermLog, message) + + def mcProgress(self, lineNr): + wx.CallAfter(self.UpdateProgress) + + def mcZChange(self, newZ): + self.currentZ = newZ + if self.cam != None: + wx.CallAfter(self.cam.takeNewImage) + wx.CallAfter(self.camPreview.Refresh) + + +class temperatureGraph(wx.Panel): + def __init__(self, parent): + super(temperatureGraph, self).__init__(parent) + + self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) + self.Bind(wx.EVT_SIZE, self.OnSize) + self.Bind(wx.EVT_PAINT, self.OnDraw) + + self.lastDraw = time.time() - 1.0 + self.points = [] + self.backBuffer = None + self.addPoint(0, 0, 0, 0) + self.SetMinSize((320, 200)) + + def OnEraseBackground(self, e): + pass + + def OnSize(self, e): + if self.backBuffer == None or self.GetSize() != self.backBuffer.GetSize(): + self.backBuffer = wx.EmptyBitmap(*self.GetSizeTuple()) + self.UpdateDrawing(True) + + def OnDraw(self, e): + dc = wx.BufferedPaintDC(self, self.backBuffer) + + def UpdateDrawing(self, force=False): + now = time.time() + if not force and now - self.lastDraw < 1.0: + return + self.lastDraw = now + dc = wx.MemoryDC() + dc.SelectObject(self.backBuffer) + dc.Clear() ++ dc.SetFont(wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)) + w, h = self.GetSizeTuple() + bgLinePen = wx.Pen('#A0A0A0') + tempPen = wx.Pen('#FF4040') + tempSPPen = wx.Pen('#FFA0A0') + tempPenBG = wx.Pen('#FFD0D0') + bedTempPen = wx.Pen('#4040FF') + bedTempSPPen = wx.Pen('#A0A0FF') + bedTempPenBG = wx.Pen('#D0D0FF') + + #Draw the background up to the current temperatures. + x0 = 0 + t0 = 0 + bt0 = 0 + tSP0 = 0 + btSP0 = 0 + for temp, tempSP, bedTemp, bedTempSP, t in self.points: + x1 = int(w - (now - t)) + for x in xrange(x0, x1 + 1): + t = float(x - x0) / float(x1 - x0 + 1) * (temp - t0) + t0 + bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0 + dc.SetPen(tempPenBG) + dc.DrawLine(x, h, x, h - (t * h / 300)) + dc.SetPen(bedTempPenBG) + dc.DrawLine(x, h, x, h - (bt * h / 300)) + t0 = temp + bt0 = bedTemp + tSP0 = tempSP + btSP0 = bedTempSP + x0 = x1 + 1 + + #Draw the grid + for x in xrange(w, 0, -30): + dc.SetPen(bgLinePen) + dc.DrawLine(x, 0, x, h) ++ tmpNr = 0 + for y in xrange(h - 1, 0, -h * 50 / 300): + dc.SetPen(bgLinePen) + dc.DrawLine(0, y, w, y) ++ dc.DrawText(str(tmpNr), 0, y - dc.GetFont().GetPixelSize().GetHeight()) ++ tmpNr += 50 + dc.DrawLine(0, 0, w, 0) + dc.DrawLine(0, 0, 0, h) + + #Draw the main lines + x0 = 0 + t0 = 0 + bt0 = 0 + tSP0 = 0 + btSP0 = 0 + for temp, tempSP, bedTemp, bedTempSP, t in self.points: + x1 = int(w - (now - t)) + for x in xrange(x0, x1 + 1): + t = float(x - x0) / float(x1 - x0 + 1) * (temp - t0) + t0 + bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0 + tSP = float(x - x0) / float(x1 - x0 + 1) * (tempSP - tSP0) + tSP0 + btSP = float(x - x0) / float(x1 - x0 + 1) * (bedTempSP - btSP0) + btSP0 + dc.SetPen(tempSPPen) + dc.DrawPoint(x, h - (tSP * h / 300)) + dc.SetPen(bedTempSPPen) + dc.DrawPoint(x, h - (btSP * h / 300)) + dc.SetPen(tempPen) + dc.DrawPoint(x, h - (t * h / 300)) + dc.SetPen(bedTempPen) + dc.DrawPoint(x, h - (bt * h / 300)) + t0 = temp + bt0 = bedTemp + tSP0 = tempSP + btSP0 = bedTempSP + x0 = x1 + 1 + + del dc + self.Refresh(eraseBackground=False) + self.Update() + + if len(self.points) > 0 and (time.time() - self.points[0][4]) > w + 20: + self.points.pop(0) + + def addPoint(self, temp, tempSP, bedTemp, bedTempSP): + if bedTemp == None: + bedTemp = 0 + if bedTempSP == None: + bedTempSP = 0 + self.points.append((temp, tempSP, bedTemp, bedTempSP, time.time())) + wx.CallAfter(self.UpdateDrawing) + + +class LogWindow(wx.Frame): + def __init__(self, logText): + super(LogWindow, self).__init__(None, title="Machine log") + self.textBox = wx.TextCtrl(self, -1, logText, style=wx.TE_MULTILINE | wx.TE_DONTWRAP | wx.TE_READONLY) + self.SetSize((500, 400)) + self.Centre() + self.Show(True)