chiark / gitweb /
Change how the quickprint profiles are defined and handled. Easier to modify&customiz...
authordaid <daid303@gmail.com>
Fri, 19 Dec 2014 14:38:21 +0000 (15:38 +0100)
committerdaid <daid303@gmail.com>
Fri, 19 Dec 2014 14:38:21 +0000 (15:38 +0100)
13 files changed:
Cura/gui/mainWindow.py
Cura/gui/sceneView.py
Cura/gui/simpleMode.py
Cura/util/objectScene.py
Cura/util/profile.py
Cura/util/resources.py
Cura/util/sliceEngine.py
resources/quickprint/materials/1_pla.ini [new file with mode: 0644]
resources/quickprint/materials/2_abs.ini [new file with mode: 0644]
resources/quickprint/profiles/1_low.ini [new file with mode: 0644]
resources/quickprint/profiles/2_normal.ini [new file with mode: 0644]
resources/quickprint/profiles/3_high.ini [new file with mode: 0644]
resources/quickprint/profiles/4_ulti.ini [new file with mode: 0644]

index efd81163b49bd2c4b667eaadf4a70aa733111548..b11ae96bc26f6880720729316dca13ea6e71407d 100644 (file)
@@ -93,6 +93,10 @@ class mainWindow(wx.Frame):
                i = self.fileMenu.Append(-1, _("Save Profile..."))
                self.normalModeOnlyItems.append(i)
                self.Bind(wx.EVT_MENU, self.OnSaveProfile, i)
+               if version.isDevVersion():
+                       i = self.fileMenu.Append(-1, "Save difference from default...")
+                       self.normalModeOnlyItems.append(i)
+                       self.Bind(wx.EVT_MENU, self.OnSaveDifferences, i)
                i = self.fileMenu.Append(-1, _("Load Profile from GCode..."))
                self.normalModeOnlyItems.append(i)
                self.Bind(wx.EVT_MENU, self.OnLoadProfileFromGcode, i)
@@ -513,10 +517,20 @@ class mainWindow(wx.Frame):
                dlg=wx.FileDialog(self, _("Select profile file to save"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
                dlg.SetWildcard("ini files (*.ini)|*.ini")
                if dlg.ShowModal() == wx.ID_OK:
-                       profileFile = dlg.GetPath()
-                       if not profileFile.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
-                               profileFile += '.ini'
-                       profile.saveProfile(profileFile)
+                       profile_filename = dlg.GetPath()
+                       if not profile_filename.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
+                               profile_filename += '.ini'
+                       profile.saveProfile(profile_filename)
+               dlg.Destroy()
+
+       def OnSaveDifferences(self, e):
+               dlg=wx.FileDialog(self, _("Select profile file to save"), os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
+               dlg.SetWildcard("ini files (*.ini)|*.ini")
+               if dlg.ShowModal() == wx.ID_OK:
+                       profile_filename = dlg.GetPath()
+                       if not profile_filename.lower().endswith('.ini'): #hack for linux, as for some reason the .ini is not appended.
+                               profile_filename += '.ini'
+                       profile.saveProfileDifferenceFromDefault(profile_filename)
                dlg.Destroy()
 
        def OnResetProfile(self, e):
index 82c11a5d28cab684028ff0f48aae2ab8d2ea5e57..bfa742779c0ca182499207c8d8eebe31b6dba0c9 100644 (file)
@@ -550,10 +550,9 @@ class SceneView(openglGui.glGuiPanel):
 
        def _onRunEngine(self, e):
                if self._isSimpleMode:
-                       self.GetTopLevelParent().simpleSettingsPanel.setupSlice()
-               self._engine.runEngine(self._scene)
-               if self._isSimpleMode:
-                       profile.resetTempOverride()
+                       self._engine.runEngine(self._scene, self.GetTopLevelParent().simpleSettingsPanel.getSettingOverrides())
+               else:
+                       self._engine.runEngine(self._scene)
 
        def _updateEngineProgress(self, progressValue):
                result = self._engine.getResult()
index 94d9dadfb880f551bfa4438d953e483e5e071d45..725a7aec18a7d9f8dd91afcc3c237306b0448a4a 100644 (file)
@@ -1,8 +1,11 @@
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import wx
+import ConfigParser as configparser
+import os.path
 
 from Cura.util import profile
+from Cura.util import resources
 
 class simpleModePanel(wx.Panel):
        "Main user interface window for Quickprint mode"
@@ -10,22 +13,30 @@ class simpleModePanel(wx.Panel):
                super(simpleModePanel, self).__init__(parent)
                self._callback = callback
 
-               #toolsMenu = wx.Menu()
-               #i = toolsMenu.Append(-1, 'Switch to Normal mode...')
-               #self.Bind(wx.EVT_MENU, self.OnNormalSwitch, i)
-               #self.menubar.Insert(1, toolsMenu, 'Normal mode')
+               self._print_profile_options = []
+               self._print_material_options = []
 
                printTypePanel = wx.Panel(self)
-               self.printTypeHigh = wx.RadioButton(printTypePanel, -1, _("High quality print"), style=wx.RB_GROUP)
-               self.printTypeNormal = wx.RadioButton(printTypePanel, -1, _("Normal quality print"))
-               self.printTypeLow = wx.RadioButton(printTypePanel, -1, _("Fast low quality print"))
-               self.printTypeJoris = wx.RadioButton(printTypePanel, -1, _("Thin walled cup or vase"))
-               self.printTypeJoris.Hide()
+               for filename in resources.getSimpleModeProfiles():
+                       cp = configparser.ConfigParser()
+                       cp.read(filename)
+                       name = os.path.basename(filename)
+                       if cp.has_option('info', 'name'):
+                               name = cp.get('info', 'name')
+                       button = wx.RadioButton(printTypePanel, -1, name, style=wx.RB_GROUP if len(self._print_profile_options) == 0 else 0)
+                       button.filename = filename
+                       self._print_profile_options.append(button)
 
                printMaterialPanel = wx.Panel(self)
-               self.printMaterialPLA = wx.RadioButton(printMaterialPanel, -1, 'PLA', style=wx.RB_GROUP)
-               self.printMaterialABS = wx.RadioButton(printMaterialPanel, -1, 'ABS')
-               self.printMaterialDiameter = wx.TextCtrl(printMaterialPanel, -1, profile.getProfileSetting('filament_diameter'))
+               for filename in resources.getSimpleModeMaterials():
+                       cp = configparser.ConfigParser()
+                       cp.read(filename)
+                       name = os.path.basename(filename)
+                       if cp.has_option('info', 'name'):
+                               name = cp.get('info', 'name')
+                       button = wx.RadioButton(printMaterialPanel, -1, name, style=wx.RB_GROUP if len(self._print_material_options) == 0 else 0)
+                       button.filename = filename
+                       self._print_material_options.append(button)
                if profile.getMachineSetting('gcode_flavor') == 'UltiGCode':
                        printMaterialPanel.Show(False)
                
@@ -36,20 +47,16 @@ class simpleModePanel(wx.Panel):
 
                sb = wx.StaticBox(printTypePanel, label=_("Select a quickprint profile:"))
                boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
-               boxsizer.Add(self.printTypeHigh)
-               boxsizer.Add(self.printTypeNormal)
-               boxsizer.Add(self.printTypeLow)
-               boxsizer.Add(self.printTypeJoris, border=5, flag=wx.TOP)
+               for button in self._print_profile_options:
+                       boxsizer.Add(button)
                printTypePanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
                printTypePanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
                sizer.Add(printTypePanel, (0,0), flag=wx.EXPAND)
 
                sb = wx.StaticBox(printMaterialPanel, label=_("Material:"))
                boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
-               boxsizer.Add(self.printMaterialPLA)
-               boxsizer.Add(self.printMaterialABS)
-               boxsizer.Add(wx.StaticText(printMaterialPanel, -1, _("Diameter:")))
-               boxsizer.Add(self.printMaterialDiameter)
+               for button in self._print_material_options:
+                       boxsizer.Add(button)
                printMaterialPanel.SetSizer(wx.BoxSizer(wx.VERTICAL))
                printMaterialPanel.GetSizer().Add(boxsizer, flag=wx.EXPAND)
                sizer.Add(printMaterialPanel, (1,0), flag=wx.EXPAND)
@@ -59,61 +66,41 @@ class simpleModePanel(wx.Panel):
                boxsizer.Add(self.printSupport)
                sizer.Add(boxsizer, (2,0), flag=wx.EXPAND)
 
-               self.printTypeNormal.SetValue(True)
-               self.printMaterialPLA.SetValue(True)
-
-               self.printTypeHigh.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-               self.printTypeNormal.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-               self.printTypeLow.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-               #self.printTypeJoris.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-
-               self.printMaterialPLA.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-               self.printMaterialABS.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
-               self.printMaterialDiameter.Bind(wx.EVT_TEXT, lambda e: self._callback())
+               for button in self._print_profile_options:
+                       button.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
+               for button in self._print_material_options:
+                       button.Bind(wx.EVT_RADIOBUTTON, lambda e: self._callback())
 
                self.printSupport.Bind(wx.EVT_CHECKBOX, lambda e: self._callback())
 
-       def setupSlice(self):
-               put = profile.setTempOverride
-               get = profile.getProfileSetting
+       def getSettingOverrides(self):
+               settings = {}
                for setting in profile.settingsList:
                        if not setting.isProfile():
                                continue
-                       profile.setTempOverride(setting.getName(), setting.getDefault())
+                       settings[setting.getName()] = setting.getDefault()
+
+               for button in self._print_profile_options:
+                       if button.GetValue():
+                               cp = configparser.ConfigParser()
+                               cp.read(button.filename)
+                               for setting in profile.settingsList:
+                                       if setting.isProfile():
+                                               if cp.has_option('profile', setting.getName()):
+                                                       settings[setting.getName()] = cp.get('profile', setting.getName())
+               if profile.getMachineSetting('gcode_flavor') != 'UltiGCode':
+                       for button in self._print_material_options:
+                               if button.GetValue():
+                                       cp = configparser.ConfigParser()
+                                       cp.read(button.filename)
+                                       for setting in profile.settingsList:
+                                               if setting.isProfile():
+                                                       if cp.has_option('profile', setting.getName()):
+                                                               settings[setting.getName()] = cp.get('profile', setting.getName())
 
                if self.printSupport.GetValue():
-                       put('support', _("Exterior Only"))
-
-               nozzle_size = float(get('nozzle_size'))
-               if self.printTypeNormal.GetValue():
-                       put('layer_height', '0.2')
-                       put('wall_thickness', nozzle_size * 2.0)
-                       put('layer_height', '0.10')
-                       put('fill_density', '20')
-               elif self.printTypeLow.GetValue():
-                       put('wall_thickness', nozzle_size * 2.5)
-                       put('layer_height', '0.20')
-                       put('fill_density', '10')
-                       put('print_speed', '60')
-                       put('cool_min_layer_time', '3')
-                       put('bottom_layer_speed', '30')
-               elif self.printTypeHigh.GetValue():
-                       put('wall_thickness', nozzle_size * 2.0)
-                       put('layer_height', '0.06')
-                       put('fill_density', '20')
-                       put('bottom_layer_speed', '15')
-               elif self.printTypeJoris.GetValue():
-                       put('wall_thickness', nozzle_size * 1.5)
-
-               put('filament_diameter', self.printMaterialDiameter.GetValue())
-               if self.printMaterialPLA.GetValue():
-                       pass
-               if self.printMaterialABS.GetValue():
-                       put('print_bed_temperature', '100')
-                       put('platform_adhesion', 'Brim')
-                       put('filament_flow', '107')
-                       put('print_temperature', '245')
-               put('plugin_config', '')
+                       settings['support'] = "Exterior Only"
+               return settings
 
        def updateProfileToControls(self):
                pass
index 358d031fbf5921bdf466e97d6a83d6e9c25a0880..dae3a6becee45c2f78aaf20032050797c5d2a576 100644 (file)
@@ -36,6 +36,9 @@ class _objectOrderFinder(object):
                for n in xrange(0, len(self._objs)):
                        if scene.checkPlatform(self._objs[n]):
                                initialList.append(n)
+               if len(initialList) == 1:
+                       self.order = initialList
+                       return
                for n in initialList:
                        if self._objs[n].getSize()[2] > gantryHeight and len(initialList) > 1:
                                self.order = None
index 376e9c2cee5d551d45650d50f81f9bffa471268d..4b765493bc9402dc4088267d5a8462f7dadeed0b 100644 (file)
@@ -740,6 +740,25 @@ def saveProfile(filename, allMachines = False):
        except:
                print "Failed to write profile file: %s" % (filename)
 
+def saveProfileDifferenceFromDefault(filename):
+       """
+               Save the current profile to an ini file. Only save the profile settings that differ from the default settings.
+       :param filename:    The ini filename to save the profile in.
+       """
+       global settingsList
+       profileParser = ConfigParser.ConfigParser()
+       profileParser.add_section('profile')
+       for set in settingsList:
+               if set.isPreference() or set.isMachineSetting() or set.isAlteration():
+                       continue
+               if set.getDefault() == set.getValue():
+                       continue
+               profileParser.set('profile', set.getName(), set.getValue().encode('utf-8'))
+       try:
+               profileParser.write(open(filename, 'w'))
+       except:
+               print "Failed to write profile file: %s" % (filename)
+
 def resetProfile():
        """ Reset the profile for the current machine to default. """
        global settingsList
index d92eb2aee8572468e2b21744bf979f658ff2b66f..0259ef97f64d2ae50ea3417a34eb1afb14199c51 100644 (file)
@@ -49,6 +49,20 @@ def getDefaultMachineProfiles():
        path = os.path.normpath(os.path.join(resourceBasePath, 'machine_profiles', '*.ini'))
        return glob.glob(path)
 
+def getSimpleModeProfiles():
+       path = os.path.normpath(os.path.join(resourceBasePath, 'quickprint', 'profiles', '*.ini'))
+       user_path = os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', 'profiles')))
+       if os.path.isdir(user_path):
+               return sorted(glob.glob(user_path))
+       return sorted(glob.glob(path))
+
+def getSimpleModeMaterials():
+       path = os.path.normpath(os.path.join(resourceBasePath, 'quickprint', 'materials', '*.ini'))
+       user_path = os.path.normpath(os.path.expanduser(os.path.join('~', '.Cura', 'quickprint', 'materials')))
+       if os.path.isdir(user_path):
+               return sorted(glob.glob(user_path))
+       return sorted(glob.glob(path))
+
 def setupLocalization(selectedLanguage = None):
        #Default to english
        languages = ['en']
index 91ba9a10804d15d5bb7bca41afcecb4d577ec06e..f16c033b49443530b7fe094e85604ac24a7faf01 100644 (file)
@@ -282,14 +282,14 @@ class Engine(object):
        def getResult(self):
                return self._result
 
-       def runEngine(self, scene):
+       def runEngine(self, scene, overrides = None):
                if len(scene.objects()) < 1:
                        return
-               self._thread = threading.Thread(target=self._runEngine, args=(scene, self._thread))
+               self._thread = threading.Thread(target=self._runEngine, args=(scene, overrides, self._thread))
                self._thread.daemon = True
                self._thread.start()
 
-       def _runEngine(self, scene, old_thread):
+       def _runEngine(self, scene, overrides, old_thread):
                if old_thread is not None:
                        if self._process is not None:
                                self._process.terminate()
@@ -303,10 +303,15 @@ class Engine(object):
 
                extruderCount = max(extruderCount, profile.minimalExtruderCount())
 
+               if overrides is not None:
+                       for k, v in overrides.items():
+                               profile.setTempOverride(k, v)
                commandList = [self._engine_executable, '-v', '-p']
                for k, v in self._engineSettings(extruderCount).iteritems():
                        commandList += ['-s', '%s=%s' % (k, str(v))]
                commandList += ['-g', '%d' % (self._serverPortNr)]
+               if overrides is not None:
+                       profile.resetTempOverride()
                self._objCount = 0
                engineModelData = []
                hash = hashlib.sha512()
diff --git a/resources/quickprint/materials/1_pla.ini b/resources/quickprint/materials/1_pla.ini
new file mode 100644 (file)
index 0000000..784aeda
--- /dev/null
@@ -0,0 +1,4 @@
+[info]
+name = PLA
+
+[profile]
diff --git a/resources/quickprint/materials/2_abs.ini b/resources/quickprint/materials/2_abs.ini
new file mode 100644 (file)
index 0000000..ccf5e9b
--- /dev/null
@@ -0,0 +1,8 @@
+[info]
+name = ABS
+
+[profile]
+print_bed_temperature = 100
+platform_adhesion = Brim
+filament_flow = 107
+print_temperature = 250
diff --git a/resources/quickprint/profiles/1_low.ini b/resources/quickprint/profiles/1_low.ini
new file mode 100644 (file)
index 0000000..7f17c6d
--- /dev/null
@@ -0,0 +1,5 @@
+[info]\r
+name = Low quality\r
+\r
+[profile]\r
+layer_height = 0.15\r
diff --git a/resources/quickprint/profiles/2_normal.ini b/resources/quickprint/profiles/2_normal.ini
new file mode 100644 (file)
index 0000000..9eb8fe0
--- /dev/null
@@ -0,0 +1,5 @@
+[info]\r
+name = Normal quality\r
+\r
+[profile]\r
+layer_height = 0.10\r
diff --git a/resources/quickprint/profiles/3_high.ini b/resources/quickprint/profiles/3_high.ini
new file mode 100644 (file)
index 0000000..478cf2f
--- /dev/null
@@ -0,0 +1,5 @@
+[info]\r
+name = High quality\r
+\r
+[profile]\r
+layer_height = 0.06\r
diff --git a/resources/quickprint/profiles/4_ulti.ini b/resources/quickprint/profiles/4_ulti.ini
new file mode 100644 (file)
index 0000000..9b6bb6a
--- /dev/null
@@ -0,0 +1,5 @@
+[info]\r
+name = Ulti quality\r
+\r
+[profile]\r
+layer_height = 0.04\r