chiark / gitweb /
Possible fix for the fluxline selection problem. Added first part of the dual-extrusi...
[cura.git] / Cura / gui / configWizard.py
index 88675d669df4e0eeab85ae08d27229987f632ec8..eab29df3d44973ba9b3676942fff3bf2a2eaa4c4 100644 (file)
@@ -13,6 +13,7 @@ from Cura.gui import firmwareInstall
 from Cura.gui import printWindow
 from Cura.util import machineCom
 from Cura.util import profile
+from Cura.util import gcodeGenerator
 from Cura.util.resources import getPathForImage
 
 class InfoBox(wx.Panel):
@@ -744,6 +745,7 @@ class configWizard(wx.wizard.Wizard):
                self.ultimakerCalibrationPage = UltimakerCalibrationPage(self)
                self.ultimakerCalibrateStepsPerEPage = UltimakerCalibrateStepsPerEPage(self)
                self.bedLevelPage = bedLevelWizardMain(self)
+               self.headOffsetCalibration = headOffsetCalibrationPage(self)
                self.repRapInfoPage = RepRapInfoPage(self)
 
                wx.wizard.WizardPageSimple.Chain(self.firstInfoPage, self.machineSelectPage)
@@ -804,6 +806,8 @@ class bedLevelWizardMain(InfoPage):
                self._wizardState = 0
 
        def AllowNext(self):
+               if self.GetParent().headOffsetCalibration is not None and int(profile.getPreference('extruder_amount')) > 1:
+                       wx.wizard.WizardPageSimple.Chain(self, self.GetParent().headOffsetCalibration)
                return True
 
        def OnResume(self, e):
@@ -894,7 +898,7 @@ class bedLevelWizardMain(InfoPage):
                        wx.CallAfter(self.resumeButton.Enable, True)
                elif self._wizardState == 9:
                        if temp[0] < profile.getProfileSettingFloat('print_temperature') - 5:
-                               wx.CallAfter(self.infoBox.SetInfo, 'Heating up printer: %d/%d' % (temp, profile.getProfileSettingFloat('print_temperature')))
+                               wx.CallAfter(self.infoBox.SetInfo, 'Heating up printer: %d/%d' % (temp[0], profile.getProfileSettingFloat('print_temperature')))
                        else:
                                wx.CallAfter(self.infoBox.SetAttention, 'The printer is hot now. Please insert some PLA filament into the printer.')
                                wx.CallAfter(self.resumeButton.Enable, True)
@@ -931,6 +935,139 @@ class bedLevelWizardMain(InfoPage):
        def mcZChange(self, newZ):
                pass
 
+class headOffsetCalibrationPage(InfoPage):
+       def __init__(self, parent):
+               super(headOffsetCalibrationPage, self).__init__(parent, "Printer head offset calibration (WIP)")
+
+               self.AddText('This wizard will help you in calibrating the printer head offsets of your dual extrusion machine')
+               self.AddSeperator()
+
+               self.connectButton = self.AddButton('Connect to printer')
+               self.comm = None
+
+               self.infoBox = self.AddInfoBox()
+               self.textEntry = self.AddTextCtrl('')
+               self.textEntry.Enable(False)
+               self.resumeButton = self.AddButton('Resume')
+               self.resumeButton.Enable(False)
+
+               self.Bind(wx.EVT_BUTTON, self.OnConnect, self.connectButton)
+               self.Bind(wx.EVT_BUTTON, self.OnResume, self.resumeButton)
+
+       def OnConnect(self, e = None):
+               if self.comm is not None:
+                       self.comm.close()
+                       del self.comm
+                       self.comm = None
+                       wx.CallAfter(self.OnConnect)
+                       return
+               self.connectButton.Enable(False)
+               self.comm = machineCom.MachineCom(callbackObject=self)
+               self.infoBox.SetBusy('Connecting to machine.')
+               self._wizardState = 0
+
+       def OnResume(self, e):
+               if self._wizardState == 2:
+                       self._wizardState = 3
+                       wx.CallAfter(self.infoBox.SetBusy, 'Printing initial calibration cross')
+
+                       w = profile.getPreferenceFloat('machine_width')
+                       d = profile.getPreferenceFloat('machine_depth')
+
+                       gcode = gcodeGenerator.gcodeGenerator()
+                       gcode.setExtrusionRate(profile.getProfileSettingFloat('nozzle_size') * 1.5, 0.3)
+                       gcode.addCmd('T0')
+                       gcode.addPrime(15)
+                       gcode.addCmd('T1')
+                       gcode.addPrime(15)
+
+                       gcode.addCmd('T0')
+                       gcode.addMove(w/2, 5, 0.3)
+                       gcode.addExtrude(w/2, d-5.0)
+                       gcode.addRetract()
+                       gcode.addMove(5, d/2)
+                       gcode.addPrime()
+                       gcode.addExtrude(w-5.0, d/2)
+                       gcode.addRetract(15)
+
+                       gcode.addCmd('T1')
+                       gcode.addMove(w/2, 5)
+                       gcode.addExtrude(w/2, d-5.0)
+                       gcode.addRetract()
+                       gcode.addMove(5, d/2)
+                       gcode.addPrime()
+                       gcode.addExtrude(w-5.0, d/2)
+                       gcode.addCmd('T0')
+                       gcode.addRetract(15)
+
+                       gcode.addMove(z=25)
+
+                       self.comm.printGCode(gcode.list())
+                       self.resumeButton.Enable(False)
+               if self._wizardState == 4:
+                       try:
+                               float(self.textEntry.GetValue())
+                       except ValueError:
+                               return
+                       profile.putPreference('extruder_offset_x1', self.textEntry.GetValue())
+                       self._wizardState = 5
+                       self.infoBox.SetAttention('Please measure the distance between the horizontal lines in millimeters.')
+                       self.textEntry.SetValue('0.0')
+                       self.textEntry.Enable(True)
+               if self._wizardState == 5:
+                       try:
+                               float(self.textEntry.GetValue())
+                       except ValueError:
+                               return
+                       profile.putPreference('extruder_offset_y1', self.textEntry.GetValue())
+                       self._wizardState = 6
+                       self.infoBox.SetBusy('Printing the fine calibration lines.')
+                       self.textEntry.SetValue('')
+                       self.textEntry.Enable(False)
+                       self.resumeButton.Enable(False)
+
+       def mcLog(self, message):
+               print 'Log:', message
+
+       def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
+               if self._wizardState == 1:
+                       if temp[0] >= 210 and temp[1] >= 210:
+                               self._wizardState = 2
+                               wx.CallAfter(self.infoBox.SetAttention, 'Please load both extruders with PLA.')
+                               wx.CallAfter(self.resumeButton.Enable, True)
+
+       def mcStateChange(self, state):
+               if self.comm is None:
+                       return
+               if self.comm.isOperational():
+                       if self._wizardState == 0:
+                               wx.CallAfter(self.infoBox.SetInfo, 'Homing printer and heating up both extruders.')
+                               self.comm.sendCommand('M105')
+                               self.comm.sendCommand('G28')
+                               self.comm.sendCommand('G1 Z15 F%d' % (profile.getProfileSettingFloat('print_speed') * 60))
+                               self.comm.sendCommand('M104 S220 T0')
+                               self.comm.sendCommand('M104 S220 T1')
+                               self._wizardState = 1
+                       if not self.comm.isPrinting():
+                               if self._wizardState == 3:
+                                       self._wizardState = 4
+                                       wx.CallAfter(self.infoBox.SetAttention, 'Please measure the distance between the vertical lines in millimeters.')
+                                       wx.CallAfter(self.textEntry.SetValue, '0.0')
+                                       wx.CallAfter(self.textEntry.Enable, True)
+                                       wx.CallAfter(self.resumeButton.Enable, True)
+                                       wx.CallAfter(self.resumeButton.SetFocus)
+               elif self.comm.isError():
+                       wx.CallAfter(self.infoBox.SetError, 'Failed to establish connection with the printer.', 'http://wiki.ultimaker.com/Cura:_Connection_problems')
+
+       def mcMessage(self, message):
+               pass
+
+       def mcProgress(self, lineNr):
+               pass
+
+       def mcZChange(self, newZ):
+               pass
+
 class bedLevelWizard(wx.wizard.Wizard):
        def __init__(self):
                super(bedLevelWizard, self).__init__(None, -1, "Bed leveling wizard")
@@ -939,6 +1076,7 @@ class bedLevelWizard(wx.wizard.Wizard):
                self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.OnPageChanging)
 
                self.mainPage = bedLevelWizardMain(self)
+               self.headOffsetCalibration = None
 
                self.FitToPage(self.mainPage)
                self.GetPageAreaSizer().Add(self.mainPage)