From: daid Date: Fri, 19 Dec 2014 14:38:21 +0000 (+0100) Subject: Change how the quickprint profiles are defined and handled. Easier to modify&customiz... X-Git-Tag: 15.01-RC4~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=eed028d643e54291dfa0800cdb888df52a4b1e59;p=cura.git Change how the quickprint profiles are defined and handled. Easier to modify&customize now. Profiles still need to be filled, waiting for final profiles from paul (bluebot) --- diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index efd81163..b11ae96b 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -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): diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index 82c11a5d..bfa74277 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -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() diff --git a/Cura/gui/simpleMode.py b/Cura/gui/simpleMode.py index 94d9dadf..725a7aec 100644 --- a/Cura/gui/simpleMode.py +++ b/Cura/gui/simpleMode.py @@ -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 diff --git a/Cura/util/objectScene.py b/Cura/util/objectScene.py index 358d031f..dae3a6be 100644 --- a/Cura/util/objectScene.py +++ b/Cura/util/objectScene.py @@ -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 diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 376e9c2c..4b765493 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -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 diff --git a/Cura/util/resources.py b/Cura/util/resources.py index d92eb2ae..0259ef97 100644 --- a/Cura/util/resources.py +++ b/Cura/util/resources.py @@ -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'] diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index 91ba9a10..f16c033b 100644 --- a/Cura/util/sliceEngine.py +++ b/Cura/util/sliceEngine.py @@ -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 index 00000000..784aedab --- /dev/null +++ b/resources/quickprint/materials/1_pla.ini @@ -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 index 00000000..ccf5e9b0 --- /dev/null +++ b/resources/quickprint/materials/2_abs.ini @@ -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 index 00000000..7f17c6d8 --- /dev/null +++ b/resources/quickprint/profiles/1_low.ini @@ -0,0 +1,5 @@ +[info] +name = Low quality + +[profile] +layer_height = 0.15 diff --git a/resources/quickprint/profiles/2_normal.ini b/resources/quickprint/profiles/2_normal.ini new file mode 100644 index 00000000..9eb8fe0a --- /dev/null +++ b/resources/quickprint/profiles/2_normal.ini @@ -0,0 +1,5 @@ +[info] +name = Normal quality + +[profile] +layer_height = 0.10 diff --git a/resources/quickprint/profiles/3_high.ini b/resources/quickprint/profiles/3_high.ini new file mode 100644 index 00000000..478cf2f7 --- /dev/null +++ b/resources/quickprint/profiles/3_high.ini @@ -0,0 +1,5 @@ +[info] +name = High quality + +[profile] +layer_height = 0.06 diff --git a/resources/quickprint/profiles/4_ulti.ini b/resources/quickprint/profiles/4_ulti.ini new file mode 100644 index 00000000..9b6bb6af --- /dev/null +++ b/resources/quickprint/profiles/4_ulti.ini @@ -0,0 +1,5 @@ +[info] +name = Ulti quality + +[profile] +layer_height = 0.04