Added feature to load a profile from a sliced GCode file.

This commit is contained in:
Daid 2012-07-05 08:46:41 +02:00
parent 1070cbf99e
commit e332443bb4
3 changed files with 25 additions and 2 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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