From: Daid Date: Thu, 5 Jul 2012 06:46:41 +0000 (+0200) Subject: Added feature to load a profile from a sliced GCode file. X-Git-Tag: 12.07~16 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e332443bb4603486bd64ff1c13a2acab0506c9b0;p=cura.git Added feature to load a profile from a sliced GCode file. --- diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index 77c16a9e..29be1411 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -53,6 +53,8 @@ class mainWindow(configBase.configWindowBase): self.Bind(wx.EVT_MENU, self.OnLoadProfile, i) i = fileMenu.Append(-1, 'Save Profile...') self.Bind(wx.EVT_MENU, self.OnSaveProfile, i) + i = fileMenu.Append(-1, 'Load Profile from GCode...') + self.Bind(wx.EVT_MENU, self.OnLoadProfileFromGcode, i) fileMenu.AppendSeparator() i = fileMenu.Append(-1, 'Reset Profile to default') self.Bind(wx.EVT_MENU, self.OnResetProfile, i) @@ -256,6 +258,23 @@ class mainWindow(configBase.configWindowBase): profile.loadGlobalProfile(profileFile) self.updateProfileToControls() dlg.Destroy() + + def OnLoadProfileFromGcode(self, e): + dlg=wx.FileDialog(self, "Select gcode file to load profile from", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST) + dlg.SetWildcard("gcode files (*.gcode)|*.gcode") + if dlg.ShowModal() == wx.ID_OK: + gcodeFile = dlg.GetPath() + f = open(gcodeFile, 'r') + hasProfile = False + for line in f: + if line.startswith(';CURA_PROFILE_STRING:'): + profile.loadGlobalProfileFromString(line[line.find(':')+1:].strip()) + hasProfile = True + if hasProfile: + self.updateProfileToControls() + else: + wx.MessageBox('No profile found in GCode file.\nThis feature only works with GCode files made by Cura 12.07 or newer.', 'Profile load error', wx.OK | wx.ICON_INFORMATION) + dlg.Destroy() def OnSaveProfile(self, e): dlg=wx.FileDialog(self, "Select profile file to save", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE) diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 8d7975ac..f40f0e33 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -435,6 +435,7 @@ def setAlterationFile(filename, value): ### Get the alteration file for output. (Used by Skeinforge) def getAlterationFileContents(filename): prefix = '' + postfix = '' alterationContents = getAlterationFile(filename) if filename == 'start.gcode': #For the start code, hack the temperature and the steps per E value into it. So the temperature is reached before the start code extrusion. @@ -445,9 +446,12 @@ def getAlterationFileContents(filename): temp = getProfileSettingFloat('print_temperature') if temp > 0 and not '{print_temperature}' in alterationContents: prefix += 'M109 S%f\n' % (temp) + elif filename == 'end.gcode': + #Append the profile string to the end of the GCode, so we can load it from the GCode file later. + postfix = ';CURA_PROFILE_STRING:%s\n' % (getGlobalProfileString()) elif filename == 'replace.csv': #Always remove the extruder on/off M codes. These are no longer needed in 5D printing. prefix = 'M101\nM103\n' - return unicode(prefix + re.sub("\{[^\}]*\}", replaceTagMatch, alterationContents).rstrip() + '\n').encode('utf-8') + return unicode(prefix + re.sub("\{[^\}]*\}", replaceTagMatch, alterationContents).rstrip() + '\n' + postfix).encode('utf-8') diff --git a/package.sh b/package.sh index 8f9955ff..a84b8d7a 100755 --- a/package.sh +++ b/package.sh @@ -16,7 +16,7 @@ BUILD_TARGET=${1:-win32} ##Do we need to create the final archive ARCHIVE_FOR_DISTRIBUTION=1 ##Which version name are we appending to the final archive -BUILD_NAME=RC4 +BUILD_NAME=12.07 TARGET_DIR=${BUILD_TARGET}-Cura-${BUILD_NAME} ##Which versions of external programs to use