From: daid303 Date: Thu, 28 Mar 2013 14:54:30 +0000 (+0100) Subject: Re-slice on setting change. Better serial port auto-detection. X-Git-Tag: 13.05~151 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=846b7bd5184e710a317ff6108301eb1514137f3a;p=cura.git Re-slice on setting change. Better serial port auto-detection. --- diff --git a/Cura/gui/configBase.py b/Cura/gui/configBase.py index 6b20cbe6..23df35bc 100644 --- a/Cura/gui/configBase.py +++ b/Cura/gui/configBase.py @@ -10,7 +10,7 @@ from Cura.util import profile class configPanelBase(wx.Panel): "A base class for configuration dialogs. Handles creation of settings, and popups" - def __init__(self, parent): + def __init__(self, parent, changeCallback = None): super(configPanelBase, self).__init__(parent) self.settingControlList = [] @@ -23,6 +23,8 @@ class configPanelBase(wx.Panel): self.popup.sizer = wx.BoxSizer() self.popup.sizer.Add(self.popup.text, flag=wx.EXPAND|wx.ALL, border=1) self.popup.SetSizer(self.popup.sizer) + + self._callback = changeCallback def CreateConfigTab(self, nb, name): leftConfigPanel, rightConfigPanel, configPanel = self.CreateConfigPanel(nb) @@ -110,6 +112,12 @@ class configPanelBase(wx.Panel): setting.SetValue(setting.setting.getValue()) self.Update() + def _validate(self): + for setting in self.settingControlList: + setting._validate() + if self._callback is not None: + self._callback() + def getLabelColumnWidth(self, panel): maxWidth = 0 for child in panel.GetChildren(): @@ -151,14 +159,14 @@ class SettingRow(): self.label.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter) self.label.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseExit) - if self.setting.getType() is types.FloatType and False: - digits = 0 - while 1 / pow(10, digits) > defaultValue: - digits += 1 - self.ctrl = floatspin.FloatSpin(panel, -1, value=float(getSettingFunc(configName)), increment=defaultValue, digits=digits, min_val=0.0) - self.ctrl.Bind(floatspin.EVT_FLOATSPIN, self.OnSettingChange) - flag = wx.EXPAND - elif self.setting.getType() is types.BooleanType: + #if self.setting.getType() is types.FloatType and False: + # digits = 0 + # while 1 / pow(10, digits) > defaultValue: + # digits += 1 + # self.ctrl = floatspin.FloatSpin(panel, -1, value=float(getSettingFunc(configName)), increment=defaultValue, digits=digits, min_val=0.0) + # self.ctrl.Bind(floatspin.EVT_FLOATSPIN, self.OnSettingChange) + # flag = wx.EXPAND + if self.setting.getType() is types.BooleanType: self.ctrl = wx.CheckBox(panel, -1, style=wx.ALIGN_RIGHT) self.SetValue(self.setting.getValue()) self.ctrl.Bind(wx.EVT_CHECKBOX, self.OnSettingChange) @@ -203,6 +211,9 @@ class SettingRow(): def OnSettingChange(self, e): self.setting.setValue(self.GetValue()) + self.panel.main._validate() + + def _validate(self): result, msg = self.setting.validate() ctrl = self.ctrl diff --git a/Cura/gui/firmwareInstall.py b/Cura/gui/firmwareInstall.py index 26cb16a3..885a2a47 100644 --- a/Cura/gui/firmwareInstall.py +++ b/Cura/gui/firmwareInstall.py @@ -66,7 +66,7 @@ class InstallFirmware(wx.Dialog): programmer = stk500v2.Stk500v2() programmer.progressCallback = self.OnProgress if self.port == 'AUTO': - for self.port in machineCom.serialList(): + for self.port in machineCom.serialList(True): try: programmer.connect(self.port) break diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index 62441765..fa32bf22 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -54,8 +54,6 @@ class mainWindow(wx.Frame): self.fileMenu = wx.Menu() i = self.fileMenu.Append(-1, 'Load model file...\tCTRL+L') self.Bind(wx.EVT_MENU, lambda e: self._showModelLoadDialog(1), i) - i = self.fileMenu.Append(-1, 'Prepare print...\tCTRL+R') - self.Bind(wx.EVT_MENU, self.OnSlice, i) i = self.fileMenu.Append(-1, 'Print...\tCTRL+P') self.Bind(wx.EVT_MENU, self.OnPrint, i) @@ -158,7 +156,7 @@ class mainWindow(wx.Frame): ##Gui components## self.simpleSettingsPanel = simpleMode.simpleModePanel(self.leftPane) - self.normalSettingsPanel = normalSettingsPanel(self.leftPane) + self.normalSettingsPanel = normalSettingsPanel(self.leftPane, lambda : self.scene.sceneUpdated()) self.leftSizer = wx.BoxSizer(wx.VERTICAL) self.leftSizer.Add(self.simpleSettingsPanel) @@ -314,27 +312,6 @@ class mainWindow(wx.Frame): def OnLoadModel4(self, e): self._showModelLoadDialog(4) - def OnSlice(self, e): - if len(self.filelist) < 1: - wx.MessageBox('You need to load a file before you can prepare it.', 'Print error', wx.OK | wx.ICON_INFORMATION) - return - isSimple = profile.getPreference('startMode') == 'Simple' - if isSimple: - #save the current profile so we can put it back latter - oldProfile = profile.getProfileString() - self.simpleSettingsPanel.setupSlice() - #Create a progress panel and add it to the window. The progress panel will start the Skein operation. - spp = sliceProgressPanel.sliceProgressPanel(self, self, self.filelist) - self.sizer.Add(spp, 0, flag=wx.EXPAND) - self.sizer.Layout() - newSize = self.GetSize() - newSize.IncBy(0, spp.GetSize().GetHeight()) - if newSize.GetWidth() < wx.GetDisplaySize()[0]: - self.SetSize(newSize) - self.progressPanelList.append(spp) - if isSimple: - profile.loadProfileFromString(oldProfile) - def OnPrint(self, e): if len(self.filelist) < 1: wx.MessageBox('You need to load a file and prepare it before you can print.', 'Print error', wx.OK | wx.ICON_INFORMATION) @@ -527,22 +504,8 @@ class mainWindow(wx.Frame): class normalSettingsPanel(configBase.configPanelBase): "Main user interface window" - def _addSettingsToPanels(self, category, left, right): - count = len(profile.getSubCategoriesFor(category)) + len(profile.getSettingsForCategory(category)) - - p = left - n = 0 - for title in profile.getSubCategoriesFor(category): - n += 1 + len(profile.getSettingsForCategory(category, title)) - if n > count / 2: - p = right - configBase.TitleRow(p, title) - for s in profile.getSettingsForCategory(category, title): - if s.checkConditions(): - configBase.SettingRow(p, s.getName()) - - def __init__(self, parent): - super(normalSettingsPanel, self).__init__(parent) + def __init__(self, parent, callback = None): + super(normalSettingsPanel, self).__init__(parent, callback) #Main tabs self.nb = wx.Notebook(self) @@ -570,6 +533,20 @@ class normalSettingsPanel(configBase.configPanelBase): self.Bind(wx.EVT_SIZE, self.OnSize) + def _addSettingsToPanels(self, category, left, right): + count = len(profile.getSubCategoriesFor(category)) + len(profile.getSettingsForCategory(category)) + + p = left + n = 0 + for title in profile.getSubCategoriesFor(category): + n += 1 + len(profile.getSettingsForCategory(category, title)) + if n > count / 2: + p = right + configBase.TitleRow(p, title) + for s in profile.getSettingsForCategory(category, title): + if s.checkConditions(): + configBase.SettingRow(p, s.getName()) + def SizeLabelWidths(self, left, right): leftWidth = self.getLabelColumnWidth(left) rightWidth = self.getLabelColumnWidth(right) diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index 451d5841..642c6a8e 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -23,18 +23,24 @@ try: except: pass -def serialList(): +def serialList(forAutoDetect=False): baselist=[] if os.name=="nt": try: key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") i=0 - while(1): - baselist+=[_winreg.EnumValue(key,i)[1]] + while True: + values = _winreg.EnumValue(key, i) + if not forAutoDetect or 'USBSER' in values[0]: + baselist+=[_winreg.EnumValue(key,i)[1]] i+=1 except: pass - baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*") + if forAutoDetect: + baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + baselist = filter(lambda s: not 'Bluetooth' in s, baselist) + else: + baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*") prev = profile.getPreference('serial_port_auto') if prev in baselist: baselist.remove(prev) @@ -264,8 +270,8 @@ class MachineCom(object): if self._port == 'AUTO': self._changeState(self.STATE_DETECT_SERIAL) programmer = stk500v2.Stk500v2() - self._log("Serial port list: %s" % (str(serialList()))) - for p in serialList(): + self._log("Serial port list: %s" % (str(serialList(True)))) + for p in serialList(True): try: self._log("Connecting to: %s" % (p)) programmer.connect(p) diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index 0a3b5a96..e26b5cce 100644 --- a/Cura/util/sliceEngine.py +++ b/Cura/util/sliceEngine.py @@ -30,6 +30,9 @@ class Slicer(object): self._process.terminate() self._thread.join() + def getGCodeFilename(self): + return self._exportFilename + def runSlicer(self, scene): self.abortSlicer() self._callback(0.0, False) @@ -50,6 +53,7 @@ class Slicer(object): f.write(mesh.vertexes.tostring()) pos = obj.getPosition() * 1000 pos += numpy.array([profile.getPreferenceFloat('machine_width') * 1000 / 2, profile.getPreferenceFloat('machine_depth') * 1000 / 2]) + commandList += ['-m', ','.join(map(str, obj._matrix.getA().flatten()))] commandList += ['-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]), '#'] self._objCount += 1 if self._objCount > 0: