chiark / gitweb /
Re-slice on setting change. Better serial port auto-detection.
authordaid303 <daid303@gmail.com>
Thu, 28 Mar 2013 14:54:30 +0000 (15:54 +0100)
committerdaid303 <daid303@gmail.com>
Thu, 28 Mar 2013 14:54:30 +0000 (15:54 +0100)
Cura/gui/configBase.py
Cura/gui/firmwareInstall.py
Cura/gui/mainWindow.py
Cura/util/machineCom.py
Cura/util/sliceEngine.py

index 6b20cbe6331ec2dd7d74bd9a670e800951b508d1..23df35bc1842396dc960981e7dd4fe51d266e9af 100644 (file)
@@ -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
index 26cb16a3b90d563032f3458587851491f6a8e39b..885a2a478f6244f28c62498eace9c492fe9a8377 100644 (file)
@@ -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
index 624417656cf636249658786a60415ace804595a7..fa32bf223efc985275dbefb751f267dd13a380bd 100644 (file)
@@ -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)
index 451d584185ea70d8203f67418330529d2efe8a00..642c6a8e9456b9d207bae490093aa9e54ebf5af1 100644 (file)
@@ -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)
index 0a3b5a960b277d1715fcaca118f760b001c2c595..e26b5cce43dd3bc7156fe00bdd3f218d4701ccd8 100644 (file)
@@ -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: