Some fixes in the GCode interperter. Start/End gcode is saved now.

This commit is contained in:
Daid 2012-02-22 20:44:00 +01:00
parent 237cf355ce
commit 5bcb8035e4
4 changed files with 104 additions and 36 deletions

View File

@ -145,7 +145,7 @@ def getSkeinPyPyConfigInformation():
'Support_Material_Choice_': 'save',
'Support_Minimum_Angle_degrees': 'save',
},'skirt': {
'Activate_Skirt': 'save',
'Skirt_line_count': 'save',
'Convex': 'ignore',
'Gap_Width_mm': 'save',
'Layers_To_index': 'ignore',

View File

@ -1,7 +1,8 @@
import wx
import sys,math,threading
import sys,math,threading,os
from fabmetheus_utilities import settings
from fabmetheus_utilities import archive
class alterationPanel(wx.Panel):
def __init__(self, parent):
@ -9,11 +10,12 @@ class alterationPanel(wx.Panel):
self.alterationFileList = ['start.gcode', 'end.gcode', 'cool_start.gcode', 'cool_end.gcode']
self.textArea = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.textArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_PROCESS_TAB)
self.textArea.SetFont(wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
self.list = wx.ListBox(self, choices=self.alterationFileList, style=wx.LB_SINGLE)
self.list.SetSelection(0)
self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list)
self.OnSelect(None)
self.textArea.Bind(wx.EVT_KILL_FOCUS, self.OnFocusLost, self.textArea)
sizer = wx.GridBagSizer()
sizer.Add(self.list, (0,0), span=(1,1), flag=wx.EXPAND)
@ -21,9 +23,17 @@ class alterationPanel(wx.Panel):
sizer.AddGrowableCol(1)
sizer.AddGrowableRow(0)
self.SetSizer(sizer)
self.loadFile(self.alterationFileList[self.list.GetSelection()])
def OnSelect(self, e):
self.loadFile(self.alterationFileList[self.list.GetSelection()])
def loadFile(self, filename):
self.textArea.SetValue(settings.getAlterationFile(filename))
def OnFocusLost(self, e):
filename = os.path.join(archive.getSkeinforgePath('alterations'), self.alterationFileList[self.list.GetSelection()])
f = open(filename, "w")
f.write(self.textArea.GetValue())
f.close()

View File

@ -61,12 +61,12 @@ class mainWindow(wx.Frame):
self.AddTitle(configPanel, "Accuracy")
self.AddSetting(configPanel, "Layer height (mm)", self.plugins['carve'].preferencesDict['Layer_Height_mm'], 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.')
self.AddTitle(configPanel, "Skirt")
self.AddSetting(configPanel, "Enable skirt", self.plugins['skirt'].preferencesDict['Activate_Skirt'])
self.AddSetting(configPanel, "Skirt distance (mm)", self.plugins['skirt'].preferencesDict['Gap_Width_mm'])
self.AddTitle(configPanel, "Fill")
self.AddSetting(configPanel, "Solid layers", self.plugins['fill'].preferencesDict['Solid_Surface_Thickness_layers'])
self.AddSetting(configPanel, "Fill Density", self.plugins['fill'].preferencesDict['Infill_Solidity_ratio'])
self.AddTitle(configPanel, "Skirt")
self.AddSetting(configPanel, "Line count", self.plugins['skirt'].preferencesDict['Skirt_line_count'])
self.AddSetting(configPanel, "Start distance (mm)", self.plugins['skirt'].preferencesDict['Gap_Width_mm'])
self.AddTitle(configPanel, "Retraction")
self.AddSetting(configPanel, "Speed (mm/s)", self.plugins['dimension'].preferencesDict['Extruder_Retraction_Speed_mm/s'])
self.AddSetting(configPanel, "Distance (mm)", self.plugins['dimension'].preferencesDict['Retraction_Distance_millimeters'])
@ -74,7 +74,7 @@ class mainWindow(wx.Frame):
self.AddSetting(configPanel, "Minimal travel (mm)", self.plugins['dimension'].preferencesDict['Minimum_Travel_for_Retraction_millimeters'])
configPanel = wx.Panel(nb);
nb.AddPage(configPanel, "Machine config")
nb.AddPage(configPanel, "Machine && Filament")
sizer = wx.GridBagSizer(2, 2)
configPanel.SetSizer(sizer)
@ -131,7 +131,7 @@ class mainWindow(wx.Frame):
sizer.Add(wx.StaticLine(panel), (sizer.GetRows()+1,1), (1,3), flag=wx.EXPAND)
sizer.SetRows(sizer.GetRows() + 2)
def AddSetting(self, panel, name, setting, help = 'TODO'):
def AddSetting(self, panel, name, setting, help = 'Help: TODO'):
"Add a setting to the configuration panel"
sizer = panel.GetSizer()
sizer.Add(wx.StaticText(panel, -1, name), (sizer.GetRows(),1), flag=wx.ALIGN_CENTER_VERTICAL)

View File

@ -1,5 +1,8 @@
import wx
import sys,math,threading
import sys
import math
import threading
import re
from wx.glcanvas import GLCanvas
try:
@ -54,49 +57,104 @@ class myGLCanvas(GLCanvas):
self.moveModel()
self.Refresh()
def getCode(self, str, id):
pos = str.find(id)
if pos < 0:
return '';
posEnd = str.find(' ', pos)
if posEnd < 0:
return str[pos+1:]
return str[pos+1:posEnd]
def getCodeInt(self, str, id):
m = re.search(id + '([^\s]+)', str)
if m == None:
return None
try:
return int(m.group(1))
except:
return None
def getCodeFloat(self, str, id):
m = re.search(id + '([^\s]+)', str)
if m == None:
return None
try:
return float(m.group(1))
except:
return None
def DoGCodeLoad(self):
f = open(self.gcodeFilename, 'r')
pos = Vector3()
posOffset = Vector3()
currentE = 0
pathList = []
currentPath = {'type': 'move', 'list': [pos.copy()]}
scale = 1.0
posAbs = True
for line in f:
G = self.getCode(line, 'G')
if G != '':
if G == '0' or G == '1':
X = self.getCode(line, 'X')
Y = self.getCode(line, 'Y')
Z = self.getCode(line, 'Z')
E = self.getCode(line, 'E')
if X != '':
pos.x = float(X)
if X != '':
pos.y = float(Y)
if Z != '':
pos.z = float(Z)
G = self.getCodeInt(line, 'G')
if G is not None:
if G == 0 or G == 1: #Move
x = self.getCodeFloat(line, 'X')
y = self.getCodeFloat(line, 'Y')
z = self.getCodeFloat(line, 'Z')
e = self.getCodeFloat(line, 'E')
if x is not None:
if posAbs:
pos.x = x * scale
else:
pos.x += x * scale
if y is not None:
if posAbs:
pos.y = y * scale
else:
pos.y += y * scale
if z is not None:
if posAbs:
pos.z = z * scale
else:
pos.z += z * scale
newPoint = pos.copy()
type = 'move'
if E != '':
newEvalue = float(E)
if newEvalue > currentE:
if e is not None:
if e > currentE:
type = 'extrude'
if newEvalue < currentE:
if e < currentE:
type = 'retract'
currentE = e
if currentPath['type'] != type:
pathList.append(currentPath)
currentPath = {'type': type, 'list': [currentPath['list'][-1]]}
currentPath['list'].append(newPoint)
elif G == 20: #Units are inches
scale = 25.4
elif G == 21: #Units are mm
scale = 1.0
elif G == 28: #Home
x = self.getCodeFloat(line, 'X')
y = self.getCodeFloat(line, 'Y')
z = self.getCodeFloat(line, 'Z')
if x is None and y is None and z is None:
pos = Vector3()
else:
if x is not None:
pos.x = 0.0
if y is not None:
pos.y = 0.0
if z is not None:
pos.z = 0.0
elif G == 90: #Absolute position
posAbs = True
elif G == 91: #Relative position
posAbs = False
elif G == 92:
x = self.getCodeFloat(line, 'X')
y = self.getCodeFloat(line, 'Y')
z = self.getCodeFloat(line, 'Z')
e = self.getCodeFloat(line, 'E')
if e is not None:
currentE = e
if x is not None:
posOffset.x = pos.x + x
if y is not None:
posOffset.y = pos.y + y
if z is not None:
posOffset.z = pos.z + z
else:
print "Unknown G code:" + G
print "Unknown G code:" + str(G)
self.pathList = pathList
self.triangleMesh = None
self.Refresh()