mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-06 08:36:07 +08:00
Merge branch 'master' of github.com:daid/SkeinPyPy
This commit is contained in:
commit
5fa46f89d5
@ -46,7 +46,7 @@ def calculateShells(setting):
|
||||
return calculateShellsImp(float(getSetting('wall_thickness')))
|
||||
|
||||
def calculateShellsBase(setting):
|
||||
return calculateShellsImp(float(getSetting('wall_thickness')) + float(getSetting('extra_base_wall_thickness')))
|
||||
return calculateShellsImp(float(getSetting('wall_thickness')) + float(getSetting('extra_base_wall_thickness', '0')))
|
||||
|
||||
def calculateShellsImp(wallThickness):
|
||||
nozzleSize = float(getSetting('nozzle_size'))
|
||||
@ -413,9 +413,6 @@ def getReadRepository(repository):
|
||||
print "Warning: Plugin: " + repository.name + " missing from SkeinPyPy info"
|
||||
return repository
|
||||
info = info[repository.name]
|
||||
if not type(info) is dict:
|
||||
print "Ignoring plugin configuration: " + repository.name
|
||||
return repository
|
||||
|
||||
#print('getReadRepository:', repository.name)
|
||||
for p in repository.preferences:
|
||||
@ -443,16 +440,28 @@ def getAlterationFileLines(fileName):
|
||||
return getAlterationLines(fileName)
|
||||
|
||||
def getAlterationLines(fileName):
|
||||
#print ('getAlterationLines:', fileName)
|
||||
return archive.getTextLines(getAlterationFile(fileName))
|
||||
|
||||
def getAlterationFile(fileName):
|
||||
"Get the file from the fileName or the lowercase fileName in the alterations directories."
|
||||
#print ('getAlterationFile:', fileName)
|
||||
prefix = ''
|
||||
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.
|
||||
#We also set our steps per E here, if configured.
|
||||
eSteps = float(getSetting('steps_per_e_unit', '0'))
|
||||
if eSteps > 0:
|
||||
prefix += 'M92 E'+str(eSteps)+'\n'
|
||||
temp = float(getSetting('print_temperature', '0'))
|
||||
if temp > 0:
|
||||
prefix += 'M109 S'+str(temp)+'\n'
|
||||
elif fileName == 'replace.csv':
|
||||
prefix = 'M101\nM103\n'
|
||||
alterationsDirectory = archive.getSkeinforgePath('alterations')
|
||||
fullFilename = os.path.join(alterationsDirectory, fileName)
|
||||
if os.path.isfile(fullFilename):
|
||||
return archive.getFileText( fullFilename )
|
||||
return ''
|
||||
return prefix + archive.getFileText( fullFilename )
|
||||
return prefix
|
||||
|
||||
####################################
|
||||
## Configuration settings classes ##
|
||||
|
@ -6,33 +6,33 @@ import ConfigParser
|
||||
|
||||
from fabmetheus_utilities import settings
|
||||
|
||||
from newui import configWindowBase
|
||||
from newui import configBase
|
||||
from newui import preview3d
|
||||
from newui import sliceProgessPanel
|
||||
from newui import alterationPanel
|
||||
from newui import validators
|
||||
|
||||
class advancedConfigWindow(configWindowBase.configWindowBase):
|
||||
class advancedConfigWindow(configBase.configWindowBase):
|
||||
"Advanced configuration window"
|
||||
def __init__(self):
|
||||
super(advancedConfigWindow, self).__init__(title='Advanced config')
|
||||
|
||||
left, right, main = self.CreateConfigPanel(self)
|
||||
|
||||
configWindowBase.TitleRow(left, "Accuracy")
|
||||
c = configWindowBase.SettingRow(left, "Extra Wall thickness for bottom/top (mm)", 'extra_base_wall_thickness', '0.0', 'Additional wall thickness of the bottom and top layers.')
|
||||
configBase.TitleRow(left, "Accuracy")
|
||||
c = configBase.SettingRow(left, "Extra Wall thickness for bottom/top (mm)", 'extra_base_wall_thickness', '0.0', 'Additional wall thickness of the bottom and top layers.')
|
||||
validators.validFloat(c, 0.0)
|
||||
validators.wallThicknessValidator(c)
|
||||
configWindowBase.TitleRow(left, "Sequence")
|
||||
c = configWindowBase.SettingRow(left, "Print order sequence", 'sequence', ['Loops > Perimeter > Infill', 'Loops > Infill > Perimeter', 'Infill > Loops > Perimeter', 'Infill > Perimeter > Loops', 'Perimeter > Infill > Loops', 'Perimeter > Loops > Infill'], 'Sequence of printing. The perimeter is the outer print edge, the loops are the insides of the walls, and the infill is the insides.');
|
||||
c = configWindowBase.SettingRow(left, "Force first layer sequence", 'force_first_layer_sequence', ['True', 'False'], 'This setting forces the order of the first layer to be \'Perimeter > Loops > Infill\'')
|
||||
configBase.TitleRow(left, "Sequence")
|
||||
c = configBase.SettingRow(left, "Print order sequence", 'sequence', ['Loops > Perimeter > Infill', 'Loops > Infill > Perimeter', 'Infill > Loops > Perimeter', 'Infill > Perimeter > Loops', 'Perimeter > Infill > Loops', 'Perimeter > Loops > Infill'], 'Sequence of printing. The perimeter is the outer print edge, the loops are the insides of the walls, and the infill is the insides.');
|
||||
c = configBase.SettingRow(left, "Force first layer sequence", 'force_first_layer_sequence', ['True', 'False'], 'This setting forces the order of the first layer to be \'Perimeter > Loops > Infill\'')
|
||||
|
||||
configWindowBase.TitleRow(left, "Infill")
|
||||
c = configWindowBase.SettingRow(left, "Infill pattern", 'infill_type', ['Line', 'Grid Circular', 'Grid Hexagonal', 'Grid Rectangular'], 'Pattern of the none-solid infill. Line is default, but grids can provide a strong print.')
|
||||
c = configWindowBase.SettingRow(left, "Solid infill top", 'solid_top', ['True', 'False'], 'Create a solid top surface, if set to false the top is filled with the fill percentage. Useful for cups/vases.')
|
||||
configBase.TitleRow(left, "Infill")
|
||||
c = configBase.SettingRow(left, "Infill pattern", 'infill_type', ['Line', 'Grid Circular', 'Grid Hexagonal', 'Grid Rectangular'], 'Pattern of the none-solid infill. Line is default, but grids can provide a strong print.')
|
||||
c = configBase.SettingRow(left, "Solid infill top", 'solid_top', ['True', 'False'], 'Create a solid top surface, if set to false the top is filled with the fill percentage. Useful for cups/vases.')
|
||||
|
||||
configWindowBase.TitleRow(left, "Joris")
|
||||
c = configWindowBase.SettingRow(left, "Joris the outer edge", 'joris', ['False', 'True'], '[Joris] is a code name for smoothing out the Z move of the outer edge. This will create a steady Z increase over the whole print. It is intended to be used with a single walled wall thickness to make cups/vases.')
|
||||
configBase.TitleRow(left, "Joris")
|
||||
c = configBase.SettingRow(left, "Joris the outer edge", 'joris', ['False', 'True'], '[Joris] is a code name for smoothing out the Z move of the outer edge. This will create a steady Z increase over the whole print. It is intended to be used with a single walled wall thickness to make cups/vases.')
|
||||
|
||||
main.Fit()
|
||||
self.Fit()
|
||||
|
@ -123,6 +123,7 @@ class SettingRow():
|
||||
sizer.SetRows(x+1)
|
||||
|
||||
def OnSettingTextChange(self, e):
|
||||
settings.putSetting(self.configName, self.GetValue())
|
||||
result = validators.SUCCESS
|
||||
msgs = []
|
||||
for validator in self.validators:
|
||||
@ -140,7 +141,6 @@ class SettingRow():
|
||||
else:
|
||||
self.ctrl.SetBackgroundColour(wx.NullColour)
|
||||
self.ctrl.Refresh()
|
||||
settings.putSetting(self.configName, self.GetValue())
|
||||
|
||||
self.validationMsg = '\n'.join(msgs)
|
||||
self.panel.main.UpdatePopup(self)
|
146
SkeinPyPy_NewUI/newui/gcodeInterpreter.py
Normal file
146
SkeinPyPy_NewUI/newui/gcodeInterpreter.py
Normal file
@ -0,0 +1,146 @@
|
||||
import sys
|
||||
import math
|
||||
import threading
|
||||
import re
|
||||
|
||||
from fabmetheus_utilities.vector3 import Vector3
|
||||
|
||||
class gcode():
|
||||
def __init__(self, filename):
|
||||
f = open(filename, 'r')
|
||||
pos = Vector3()
|
||||
posOffset = Vector3()
|
||||
currentE = 0
|
||||
pathList = []
|
||||
scale = 1.0
|
||||
posAbs = True
|
||||
feedRate = 3600
|
||||
pathType = 'CUSTOM';
|
||||
layerNr = 0; #Note layer 0 will be the start code.
|
||||
startCodeDone = False
|
||||
currentPath = {'type': 'move', 'pathType': pathType, 'list': [pos.copy()], 'layerNr': layerNr}
|
||||
for line in f:
|
||||
if line.startswith(';TYPE:'):
|
||||
pathType = line[6:].strip()
|
||||
if pathType != "CUSTOM":
|
||||
startCodeDone = True
|
||||
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')
|
||||
f = self.getCodeFloat(line, 'F')
|
||||
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:
|
||||
oldZ = pos.z
|
||||
if posAbs:
|
||||
pos.z = z * scale
|
||||
else:
|
||||
pos.z += z * scale
|
||||
if oldZ != pos.z and startCodeDone:
|
||||
layerNr += 1
|
||||
if f is not None:
|
||||
feedRate = f
|
||||
newPoint = pos.copy()
|
||||
moveType = 'move'
|
||||
if e is not None:
|
||||
if e > currentE:
|
||||
moveType = 'extrude'
|
||||
if e < currentE:
|
||||
moveType = 'retract'
|
||||
currentE = e
|
||||
if currentPath['type'] != moveType or currentPath['pathType'] != pathType:
|
||||
pathList.append(currentPath)
|
||||
currentPath = {'type': moveType, 'pathType': pathType, 'list': [currentPath['list'][-1]], 'layerNr': layerNr}
|
||||
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:" + str(G)
|
||||
else:
|
||||
M = self.getCodeInt(line, 'M')
|
||||
if M is not None:
|
||||
if M == 1: #Message with possible wait (ignored)
|
||||
pass
|
||||
elif M == 84: #Disable step drivers
|
||||
pass
|
||||
elif M == 92: #Set steps per unit
|
||||
pass
|
||||
elif M == 104: #Set temperature, no wait
|
||||
pass
|
||||
elif M == 105: #Get temperature
|
||||
pass
|
||||
elif M == 106: #Enable fan
|
||||
pass
|
||||
elif M == 107: #Disable fan
|
||||
pass
|
||||
elif M == 108: #Extruder RPM (these should not be in the final GCode, but they are)
|
||||
pass
|
||||
elif M == 113: #Extruder PWM (these should not be in the final GCode, but they are)
|
||||
pass
|
||||
else:
|
||||
print "Unknown M code:" + str(M)
|
||||
self.layerCount = layerNr
|
||||
self.pathList = pathList
|
||||
|
||||
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
|
||||
|
@ -6,7 +6,7 @@ import ConfigParser
|
||||
|
||||
from fabmetheus_utilities import settings
|
||||
|
||||
from newui import configWindowBase
|
||||
from newui import configBase
|
||||
from newui import advancedConfig
|
||||
from newui import preview3d
|
||||
from newui import sliceProgessPanel
|
||||
@ -18,7 +18,7 @@ def main():
|
||||
mainWindow()
|
||||
app.MainLoop()
|
||||
|
||||
class mainWindow(configWindowBase.configWindowBase):
|
||||
class mainWindow(configBase.configWindowBase):
|
||||
"Main user interface window"
|
||||
def __init__(self):
|
||||
super(mainWindow, self).__init__(title='SkeinPyPy')
|
||||
@ -42,7 +42,7 @@ class mainWindow(configWindowBase.configWindowBase):
|
||||
self.SetMenuBar(menubar)
|
||||
|
||||
self.lastPath = ""
|
||||
self.filename = configWindowBase.getPreference('lastFile', None)
|
||||
self.filename = configBase.getPreference('lastFile', None)
|
||||
self.progressPanelList = []
|
||||
|
||||
#Preview window
|
||||
@ -53,87 +53,90 @@ class mainWindow(configWindowBase.configWindowBase):
|
||||
|
||||
(left, right) = self.CreateConfigTab(nb, 'Print config')
|
||||
|
||||
configWindowBase.TitleRow(left, "Accuracy")
|
||||
c = configWindowBase.SettingRow(left, "Layer height (mm)", 'layer_height', '0.2', 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.')
|
||||
configBase.TitleRow(left, "Accuracy")
|
||||
c = configBase.SettingRow(left, "Layer height (mm)", 'layer_height', '0.2', 'Layer height in millimeters.\n0.2 is a good value for quick prints.\n0.1 gives high quality prints.')
|
||||
validators.validFloat(c, 0.0)
|
||||
validators.warningAbove(c, 0.31, "Thicker layers then 0.3mm usually give bad results and are not recommended.")
|
||||
c = configWindowBase.SettingRow(left, "Wall thickness (mm)", 'wall_thickness', '0.8', 'Thickness of the walls.\nThis is used in combination with the nozzle size to define the number\nof perimeter lines and the thickness of those perimeter lines.')
|
||||
c = configBase.SettingRow(left, "Wall thickness (mm)", 'wall_thickness', '0.8', 'Thickness of the walls.\nThis is used in combination with the nozzle size to define the number\nof perimeter lines and the thickness of those perimeter lines.')
|
||||
validators.validFloat(c, 0.0)
|
||||
validators.wallThicknessValidator(c)
|
||||
configBase.settingNotify(c, self.preview3d.updateWallLineWidth)
|
||||
|
||||
configWindowBase.TitleRow(left, "Fill")
|
||||
c = configWindowBase.SettingRow(left, "Bottom/Top thickness (mm)", 'solid_layer_thickness', '0.6', 'This controls the thickness of the bottom and top layers, the amount of solid layers put down is calculated by the layer thickness and this value.\nHaving this value a multiply of the layer thickness makes sense. And keep it near your wall thickness to make an evenly strong part.')
|
||||
configBase.TitleRow(left, "Fill")
|
||||
c = configBase.SettingRow(left, "Bottom/Top thickness (mm)", 'solid_layer_thickness', '0.6', 'This controls the thickness of the bottom and top layers, the amount of solid layers put down is calculated by the layer thickness and this value.\nHaving this value a multiply of the layer thickness makes sense. And keep it near your wall thickness to make an evenly strong part.')
|
||||
validators.validFloat(c, 0.0)
|
||||
c = configWindowBase.SettingRow(left, "Fill Density (%)", 'fill_density', '20', 'This controls how densily filled the insides of your print will be. For a solid part use 100%, for an empty part use 0%. A value around 20% is usually enough')
|
||||
c = configBase.SettingRow(left, "Fill Density (%)", 'fill_density', '20', 'This controls how densily filled the insides of your print will be. For a solid part use 100%, for an empty part use 0%. A value around 20% is usually enough')
|
||||
validators.validFloat(c, 0.0, 100.0)
|
||||
|
||||
configWindowBase.TitleRow(left, "Skirt")
|
||||
c = configWindowBase.SettingRow(left, "Line count", 'skirt_line_count', '1', 'The skirt is a line drawn around the object at the first layer. This helps to prime your extruder, and to see if the object fits on your platform.\nSetting this to 0 will disable the skirt.')
|
||||
configBase.TitleRow(left, "Skirt")
|
||||
c = configBase.SettingRow(left, "Line count", 'skirt_line_count', '1', 'The skirt is a line drawn around the object at the first layer. This helps to prime your extruder, and to see if the object fits on your platform.\nSetting this to 0 will disable the skirt.')
|
||||
validators.validInt(c, 0, 10)
|
||||
c = configWindowBase.SettingRow(left, "Start distance (mm)", 'skirt_gap', '6.0', 'The distance between the skirt and the first layer.\nThis is the minimal distance, multiple skirt lines will be put outwards from this distance.')
|
||||
c = configBase.SettingRow(left, "Start distance (mm)", 'skirt_gap', '6.0', 'The distance between the skirt and the first layer.\nThis is the minimal distance, multiple skirt lines will be put outwards from this distance.')
|
||||
validators.validFloat(c, 0.0)
|
||||
|
||||
configWindowBase.TitleRow(right, "Speed")
|
||||
c = configWindowBase.SettingRow(right, "Print speed (mm/s)", 'print_speed', '50', 'Speed at which printing happens. A well adjusted Ultimaker can reach 150mm/s, but for good quality prints you want to print slower. Printing speed depends on a lot of factors. So you will be experimenting with optimal settings for this.')
|
||||
configBase.TitleRow(right, "Speed")
|
||||
c = configBase.SettingRow(right, "Print speed (mm/s)", 'print_speed', '50', 'Speed at which printing happens. A well adjusted Ultimaker can reach 150mm/s, but for good quality prints you want to print slower. Printing speed depends on a lot of factors. So you will be experimenting with optimal settings for this.')
|
||||
validators.validFloat(c, 1.0)
|
||||
validators.warningAbove(c, 150.0, "It is highly unlikely that your machine can achieve a printing speed above 150mm/s")
|
||||
|
||||
#Printing temperature is a problem right now, as our start code depends on a heated head.
|
||||
#configWindowBase.TitleRow(right, "Temperature")
|
||||
#c = configWindowBase.SettingRow(right, "Printing temperature", 'print_temperature', '0', 'Temperature used for printing. Set at 0 to pre-heat yourself')
|
||||
#validators.validFloat(c, 0.0, 350.0)
|
||||
#validators.warningAbove(c, 260.0, "Temperatures above 260C could damage your machine.")
|
||||
configBase.TitleRow(right, "Temperature")
|
||||
c = configBase.SettingRow(right, "Printing temperature", 'print_temperature', '0', 'Temperature used for printing. Set at 0 to pre-heat yourself')
|
||||
validators.validFloat(c, 0.0, 340.0)
|
||||
validators.warningAbove(c, 260.0, "Temperatures above 260C could damage your machine, be careful!")
|
||||
|
||||
configWindowBase.TitleRow(right, "Support")
|
||||
c = configWindowBase.SettingRow(right, "Support type", 'support', ['None', 'Exterior only', 'Everywhere', 'Empty layers only'], 'Type of support structure build.\nNone does not do any support.\nExterior only only creates support on the outside.\nEverywhere creates support even on the insides of the model.\nOnly on empty layers is for stacked objects.')
|
||||
configBase.TitleRow(right, "Support")
|
||||
c = configBase.SettingRow(right, "Support type", 'support', ['None', 'Exterior only', 'Everywhere', 'Empty layers only'], 'Type of support structure build.\nNone does not do any support.\nExterior only only creates support on the outside.\nEverywhere creates support even on the insides of the model.\nOnly on empty layers is for stacked objects.')
|
||||
|
||||
configBase.TitleRow(right, "Filament")
|
||||
c = configBase.SettingRow(right, "Diameter (mm)", 'filament_diameter', '2.98', 'Diameter of your filament, as accurately as possible.\nIf you cannot measure this value you will have to callibrate it, a higher number means less extrusion, a smaller number generates more extrusion.')
|
||||
validators.validFloat(c, 1.0)
|
||||
c = configBase.SettingRow(right, "Packing Density", 'filament_density', '1.00', 'Packing density of your filament. This should be 1.00 for PLA and 0.85 for ABS')
|
||||
validators.validFloat(c, 0.5, 1.5)
|
||||
|
||||
(left, right) = self.CreateConfigTab(nb, 'Machine && Filament')
|
||||
(left, right) = self.CreateConfigTab(nb, 'Machine config')
|
||||
|
||||
configWindowBase.TitleRow(left, "Machine size")
|
||||
c = configWindowBase.SettingRow(left, "Machine center X (mm)", 'machine_center_x', '100', 'The center of your machine, your print will be placed at this location')
|
||||
configBase.TitleRow(left, "Machine size")
|
||||
c = configBase.SettingRow(left, "Machine center X (mm)", 'machine_center_x', '100', 'The center of your machine, your print will be placed at this location')
|
||||
validators.validInt(c, 10)
|
||||
configWindowBase.settingNotify(c, self.preview3d.updateCenterX)
|
||||
c = configWindowBase.SettingRow(left, "Machine center Y (mm)", 'machine_center_y', '100', 'The center of your machine, your print will be placed at this location')
|
||||
configBase.settingNotify(c, self.preview3d.updateCenterX)
|
||||
c = configBase.SettingRow(left, "Machine center Y (mm)", 'machine_center_y', '100', 'The center of your machine, your print will be placed at this location')
|
||||
validators.validInt(c, 10)
|
||||
configWindowBase.settingNotify(c, self.preview3d.updateCenterY)
|
||||
configBase.settingNotify(c, self.preview3d.updateCenterY)
|
||||
#self.AddSetting(left, "Width (mm)", settings.IntSpin().getFromValue(10, "machine_width", None, 1000, 205))
|
||||
#self.AddSetting(left, "Depth (mm)", settings.IntSpin().getFromValue(10, "machine_depth", None, 1000, 205))
|
||||
#self.AddSetting(left, "Height (mm)", settings.IntSpin().getFromValue(10, "machine_height", None, 1000, 200))
|
||||
|
||||
configWindowBase.TitleRow(left, "Machine nozzle")
|
||||
c = configWindowBase.SettingRow(left, "Nozzle size (mm)", 'nozzle_size', '0.4', 'The nozzle size is very important, this is used to calculate the line width of the infill, and used to calculate the amount of outside wall lines and thickness for the wall thickness you entered in the print settings.')
|
||||
configBase.TitleRow(left, "Machine nozzle")
|
||||
c = configBase.SettingRow(left, "Nozzle size (mm)", 'nozzle_size', '0.4', 'The nozzle size is very important, this is used to calculate the line width of the infill, and used to calculate the amount of outside wall lines and thickness for the wall thickness you entered in the print settings.')
|
||||
validators.validFloat(c, 0.1, 1.0)
|
||||
configBase.settingNotify(c, self.preview3d.updateWallLineWidth)
|
||||
configBase.settingNotify(c, self.preview3d.updateInfillLineWidth)
|
||||
|
||||
configWindowBase.TitleRow(left, "Retraction")
|
||||
c = configWindowBase.SettingRow(left, "Minimal travel (mm)", 'retraction_min_travel', '5.0', 'Minimal amount of travel needed for a retraction to happen at all. To make sure you do not get a lot of retractions in a small area')
|
||||
configBase.TitleRow(left, "Retraction")
|
||||
c = configBase.SettingRow(left, "Minimal travel (mm)", 'retraction_min_travel', '5.0', 'Minimal amount of travel needed for a retraction to happen at all. To make sure you do not get a lot of retractions in a small area')
|
||||
validators.validFloat(c, 0.0)
|
||||
c = configWindowBase.SettingRow(left, "Speed (mm/s)", 'retraction_speed', '13.5', 'Speed at which the filament is retracted')
|
||||
c = configBase.SettingRow(left, "Speed (mm/s)", 'retraction_speed', '13.5', 'Speed at which the filament is retracted')
|
||||
validators.validFloat(c, 0.1)
|
||||
c = configWindowBase.SettingRow(left, "Distance (mm)", 'retraction_amount', '0.0', 'Amount of retraction, set at 0 for no retraction at all.')
|
||||
c = configBase.SettingRow(left, "Distance (mm)", 'retraction_amount', '0.0', 'Amount of retraction, set at 0 for no retraction at all.')
|
||||
validators.validFloat(c, 0.0)
|
||||
c = configWindowBase.SettingRow(left, "Extra length on start (mm)", 'retraction_extra', '0.0', 'Extra extrusion amount when restarting after a retraction, to better "Prime" your extruder')
|
||||
c = configBase.SettingRow(left, "Extra length on start (mm)", 'retraction_extra', '0.0', 'Extra extrusion amount when restarting after a retraction, to better "Prime" your extruder')
|
||||
validators.validFloat(c, 0.0)
|
||||
|
||||
configWindowBase.TitleRow(right, "Speed")
|
||||
c = configWindowBase.SettingRow(right, "Travel speed (mm/s)", 'travel_speed', '150', 'Speed at which travel moves are done')
|
||||
configBase.TitleRow(right, "Speed")
|
||||
c = configBase.SettingRow(right, "Travel speed (mm/s)", 'travel_speed', '150', 'Speed at which travel moves are done')
|
||||
validators.validFloat(c, 1.0)
|
||||
validators.warningAbove(c, 300.0, "It is highly unlikely that your machine can achieve a travel speed above 150mm/s")
|
||||
c = configWindowBase.SettingRow(right, "Max Z speed (mm/s)", 'max_z_speed', '1.0', 'Speed at which Z moves are done.')
|
||||
c = configBase.SettingRow(right, "Max Z speed (mm/s)", 'max_z_speed', '1.0', 'Speed at which Z moves are done.')
|
||||
validators.validFloat(c, 0.5)
|
||||
c = configWindowBase.SettingRow(right, "Bottom layer speed (mm/s)", 'bottom_layer_speed', '25', 'Print speed for the bottom layer, you want to print the first layer slower so it sticks better to the printer bed.')
|
||||
c = configBase.SettingRow(right, "Bottom layer speed (mm/s)", 'bottom_layer_speed', '25', 'Print speed for the bottom layer, you want to print the first layer slower so it sticks better to the printer bed.')
|
||||
validators.validFloat(c, 0.0)
|
||||
|
||||
configWindowBase.TitleRow(right, "Cool")
|
||||
configBase.TitleRow(right, "Cool")
|
||||
#c = SettingRow(right, "Cool type", self.plugins['cool'].preferencesDict['Cool_Type'])
|
||||
c = configWindowBase.SettingRow(right, "Minimal layer time (sec)", 'cool_min_layer_time', '10', 'Minimum time spend in a layer, gives the layer time to cool down before the next layer is put on top. If the layer will be placed down too fast the printer will slow down to make sure it has spend atleast this amount of seconds printing this layer.')
|
||||
c = configBase.SettingRow(right, "Minimal layer time (sec)", 'cool_min_layer_time', '10', 'Minimum time spend in a layer, gives the layer time to cool down before the next layer is put on top. If the layer will be placed down too fast the printer will slow down to make sure it has spend atleast this amount of seconds printing this layer.')
|
||||
validators.validFloat(c, 0.0)
|
||||
|
||||
configWindowBase.TitleRow(right, "Filament")
|
||||
c = configWindowBase.SettingRow(right, "Diameter (mm)", 'filament_diameter', '2.98', 'Diameter of your filament, as accurately as possible.\nIf you cannot measure this value you will have to callibrate it, a higher number means less extrusion, a smaller number generates more extrusion.')
|
||||
validators.validFloat(c, 1.0)
|
||||
c = configWindowBase.SettingRow(right, "Packing Density", 'filament_density', '1.00', 'Packing density of your filament. This should be 1.00 for PLA and 0.85 for ABS')
|
||||
validators.validFloat(c, 0.5, 1.5)
|
||||
|
||||
nb.AddPage(alterationPanel.alterationPanel(nb), "Start/End-GCode")
|
||||
|
||||
# load and slice buttons.
|
||||
@ -187,7 +190,7 @@ class mainWindow(configWindowBase.configWindowBase):
|
||||
dlg.SetWildcard("OBJ, STL files (*.stl;*.obj)|*.stl;*.obj")
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
self.filename=dlg.GetPath()
|
||||
configWindowBase.putPreference('lastFile', self.filename)
|
||||
configBase.putPreference('lastFile', self.filename)
|
||||
if not(os.path.exists(self.filename)):
|
||||
return
|
||||
self.lastPath = os.path.split(self.filename)[0]
|
||||
|
@ -16,6 +16,8 @@ except:
|
||||
|
||||
from fabmetheus_utilities.fabmetheus_tools import fabmetheus_interpret
|
||||
from fabmetheus_utilities.vector3 import Vector3
|
||||
from fabmetheus_utilities import settings
|
||||
from newui import gcodeInterpreter
|
||||
|
||||
class previewPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
@ -27,16 +29,32 @@ class previewPanel(wx.Panel):
|
||||
self.glCanvas = PreviewGLCanvas(self)
|
||||
self.init = 0
|
||||
self.triangleMesh = None
|
||||
self.pathList = None
|
||||
self.gcode = None
|
||||
self.machineSize = Vector3(210, 210, 200)
|
||||
self.machineCenter = Vector3(0, 0, 0)
|
||||
|
||||
tb = wx.ToolBar( self, -1 )
|
||||
self.ToolBar = tb
|
||||
tb.SetToolBitmapSize( ( 21, 21 ) )
|
||||
transparentButton = wx.Button(tb, -1, "T", size=(21,21))
|
||||
tb.AddControl(transparentButton)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnConfigClick, transparentButton)
|
||||
|
||||
button = wx.Button(tb, -1, "3D", size=(21*2,21))
|
||||
tb.AddControl(button)
|
||||
self.Bind(wx.EVT_BUTTON, self.On3DClick, button)
|
||||
|
||||
button = wx.Button(tb, -1, "Top", size=(21*2,21))
|
||||
tb.AddControl(button)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnTopClick, button)
|
||||
|
||||
self.transparentButton = wx.Button(tb, -1, "T", size=(21,21))
|
||||
tb.AddControl(self.transparentButton)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnConfigClick, self.transparentButton)
|
||||
|
||||
self.layerSpin = wx.SpinCtrl(tb, -1, '', size=(21*4,21), style=wx.SP_ARROW_KEYS)
|
||||
tb.AddControl(self.layerSpin)
|
||||
self.Bind(wx.EVT_SPINCTRL, self.OnLayerNrChange, self.layerSpin)
|
||||
self.transparentButton.Show(False)
|
||||
self.layerSpin.Show(False)
|
||||
|
||||
tb.Realize()
|
||||
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
@ -44,6 +62,24 @@ class previewPanel(wx.Panel):
|
||||
sizer.Add(self.glCanvas, 1, flag=wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
def On3DClick(self, e):
|
||||
self.glCanvas.yaw = 30
|
||||
self.glCanvas.pitch = 60
|
||||
self.glCanvas.zoom = 150
|
||||
self.glCanvas.view3D = True
|
||||
self.glCanvas.Refresh()
|
||||
|
||||
def OnTopClick(self, e):
|
||||
self.glCanvas.view3D = False
|
||||
self.glCanvas.zoom = 100
|
||||
self.glCanvas.offsetX = 0
|
||||
self.glCanvas.offsetY = 0
|
||||
self.glCanvas.Refresh()
|
||||
|
||||
def OnLayerNrChange(self, e):
|
||||
self.modelDirty = True
|
||||
self.glCanvas.Refresh()
|
||||
|
||||
def updateCenterX(self, x):
|
||||
self.machineCenter.x = x
|
||||
self.moveModel()
|
||||
@ -54,6 +90,12 @@ class previewPanel(wx.Panel):
|
||||
self.moveModel()
|
||||
self.glCanvas.Refresh()
|
||||
|
||||
def updateWallLineWidth(self, setting):
|
||||
self.glCanvas.lineWidth = settings.calculateEdgeWidth(setting)
|
||||
|
||||
def updateInfillLineWidth(self, setting):
|
||||
self.glCanvas.infillLineWidth = settings.getSetting('nozzle_size')
|
||||
|
||||
def loadModelFile(self, filename):
|
||||
self.modelFilename = filename
|
||||
#Do the STL file loading in a background thread so we don't block the UI.
|
||||
@ -69,116 +111,25 @@ class previewPanel(wx.Panel):
|
||||
def DoModelLoad(self):
|
||||
self.modelDirty = False
|
||||
self.triangleMesh = fabmetheus_interpret.getCarving(self.modelFilename)
|
||||
self.pathList = None
|
||||
self.gcode = None
|
||||
self.moveModel()
|
||||
self.glCanvas.Refresh()
|
||||
|
||||
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
|
||||
wx.CallAfter(self.updateToolbar)
|
||||
wx.CallAfter(self.glCanvas.Refresh)
|
||||
|
||||
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
|
||||
pathType = 'CUSTOM';
|
||||
for line in f:
|
||||
if line.startswith(';TYPE:'):
|
||||
pathType = line[6:].strip()
|
||||
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 is not None:
|
||||
if e > currentE:
|
||||
type = 'extrude'
|
||||
if e < currentE:
|
||||
type = 'retract'
|
||||
currentE = e
|
||||
if currentPath['type'] != type:
|
||||
pathList.append(currentPath)
|
||||
currentPath = {'type': type, 'pathType': pathType, '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:" + str(G)
|
||||
gcode = gcodeInterpreter.gcode(self.gcodeFilename)
|
||||
self.modelDirty = False
|
||||
self.pathList = pathList
|
||||
self.gcode = gcode
|
||||
self.triangleMesh = None
|
||||
self.modelDirty = True
|
||||
self.glCanvas.Refresh()
|
||||
wx.CallAfter(self.updateToolbar)
|
||||
wx.CallAfter(self.glCanvas.Refresh)
|
||||
|
||||
def updateToolbar(self):
|
||||
self.transparentButton.Show(self.triangleMesh != None)
|
||||
self.layerSpin.Show(self.gcode != None)
|
||||
if self.gcode != None:
|
||||
self.layerSpin.SetRange(1, self.gcode.layerCount)
|
||||
|
||||
def OnConfigClick(self, e):
|
||||
self.glCanvas.renderTransparent = not self.glCanvas.renderTransparent
|
||||
@ -207,27 +158,45 @@ class PreviewGLCanvas(GLCanvas):
|
||||
wx.EVT_SIZE(self, self.OnSize)
|
||||
wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
wx.EVT_MOTION(self, self.OnMouseMotion)
|
||||
wx.EVT_MOUSEWHEEL(self, self.OnMouseWheel)
|
||||
self.yaw = 30
|
||||
self.pitch = 60
|
||||
self.zoom = 150
|
||||
self.offsetX = 0
|
||||
self.offsetY = 0
|
||||
self.lineWidth = 0.4
|
||||
self.fillLineWidth = 0.4
|
||||
self.view3D = True
|
||||
self.renderTransparent = False
|
||||
self.modelDisplayList = None
|
||||
|
||||
def OnMouseMotion(self,e):
|
||||
if e.Dragging() and e.LeftIsDown():
|
||||
self.yaw += e.GetX() - self.oldX
|
||||
self.pitch -= e.GetY() - self.oldY
|
||||
if self.pitch > 170:
|
||||
self.pitch = 170
|
||||
if self.pitch < 10:
|
||||
self.pitch = 10
|
||||
if self.view3D:
|
||||
self.yaw += e.GetX() - self.oldX
|
||||
self.pitch -= e.GetY() - self.oldY
|
||||
if self.pitch > 170:
|
||||
self.pitch = 170
|
||||
if self.pitch < 10:
|
||||
self.pitch = 10
|
||||
else:
|
||||
self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2
|
||||
self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2
|
||||
self.Refresh()
|
||||
if e.Dragging() and e.RightIsDown():
|
||||
self.zoom += e.GetY() - self.oldY
|
||||
if self.zoom < 1:
|
||||
self.zoom = 1
|
||||
self.Refresh()
|
||||
self.oldX = e.GetX()
|
||||
self.oldY = e.GetY()
|
||||
|
||||
def OnMouseWheel(self,e):
|
||||
self.zoom *= 1 - float(e.GetWheelRotation() / e.GetWheelDelta()) / 10
|
||||
if self.zoom < 1:
|
||||
self.zoom = 1
|
||||
self.Refresh()
|
||||
|
||||
def OnEraseBackground(self,event):
|
||||
pass
|
||||
|
||||
@ -288,28 +257,66 @@ class PreviewGLCanvas(GLCanvas):
|
||||
glVertex3f(0, machineSize.y, machineSize.z)
|
||||
glEnd()
|
||||
|
||||
if self.parent.pathList != None:
|
||||
if self.parent.gcode != None:
|
||||
if self.modelDisplayList == None:
|
||||
self.modelDisplayList = glGenLists(1);
|
||||
if self.parent.modelDirty:
|
||||
self.parent.modelDirty = False
|
||||
glNewList(self.modelDisplayList, GL_COMPILE)
|
||||
for path in self.parent.pathList:
|
||||
for path in self.parent.gcode.pathList:
|
||||
c = 1.0
|
||||
if path['layerNr'] != self.parent.layerSpin.GetValue():
|
||||
if path['layerNr'] < self.parent.layerSpin.GetValue():
|
||||
c = 0.5 - (self.parent.layerSpin.GetValue() - path['layerNr']) * 0.1
|
||||
if c < -0.5:
|
||||
continue
|
||||
if c < 0.1:
|
||||
c = 0.1
|
||||
else:
|
||||
break
|
||||
if path['type'] == 'move':
|
||||
glColor3f(0,0,1)
|
||||
glColor3f(0,0,c)
|
||||
if path['type'] == 'extrude':
|
||||
if path['pathType'] == 'FILL':
|
||||
glColor3f(0.5,0.5,0)
|
||||
glColor3f(c/2,c/2,0)
|
||||
elif path['pathType'] == 'WALL-INNER':
|
||||
glColor3f(0,1,0)
|
||||
glColor3f(0,c,0)
|
||||
else:
|
||||
glColor3f(1,0,0)
|
||||
glColor3f(c,0,0)
|
||||
if path['type'] == 'retract':
|
||||
glColor3f(0,1,1)
|
||||
glBegin(GL_LINE_STRIP)
|
||||
for v in path['list']:
|
||||
glVertex3f(v.x, v.y, v.z)
|
||||
glEnd()
|
||||
glColor3f(0,c,c)
|
||||
if path['type'] == 'extrude':
|
||||
if path['pathType'] == 'FILL':
|
||||
lineWidth = self.fillLineWidth / 2
|
||||
else:
|
||||
lineWidth = self.lineWidth / 2
|
||||
for i in xrange(0, len(path['list'])-1):
|
||||
v0 = path['list'][i]
|
||||
v1 = path['list'][i+1]
|
||||
normal = (v0 - v1).cross(Vector3(0,0,1))
|
||||
normal.normalize()
|
||||
v2 = v0 + normal * lineWidth
|
||||
v3 = v1 + normal * lineWidth
|
||||
v0 = v0 - normal * lineWidth
|
||||
v1 = v1 - normal * lineWidth
|
||||
|
||||
glBegin(GL_QUADS)
|
||||
glVertex3f(v0.x, v0.y, v0.z - 0.001)
|
||||
glVertex3f(v1.x, v1.y, v1.z - 0.001)
|
||||
glVertex3f(v3.x, v3.y, v3.z - 0.001)
|
||||
glVertex3f(v2.x, v2.y, v2.z - 0.001)
|
||||
glEnd()
|
||||
for v in path['list']:
|
||||
glBegin(GL_TRIANGLE_FAN)
|
||||
glVertex3f(v.x, v.y, v.z - 0.001)
|
||||
for i in xrange(0, 16+1):
|
||||
glVertex3f(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.001)
|
||||
glEnd()
|
||||
else:
|
||||
glBegin(GL_LINE_STRIP)
|
||||
for v in path['list']:
|
||||
glVertex3f(v.x, v.y, v.z)
|
||||
glEnd()
|
||||
glEndList()
|
||||
glCallList(self.modelDisplayList)
|
||||
|
||||
@ -324,9 +331,10 @@ class PreviewGLCanvas(GLCanvas):
|
||||
v1 = self.parent.triangleMesh.vertexes[face.vertexIndexes[0]]
|
||||
v2 = self.parent.triangleMesh.vertexes[face.vertexIndexes[1]]
|
||||
v3 = self.parent.triangleMesh.vertexes[face.vertexIndexes[2]]
|
||||
normal = (v2 - v1).cross(v3 - v1)
|
||||
normal.normalize()
|
||||
glNormal3f(normal.x, normal.y, normal.z)
|
||||
if not hasattr(face, 'normal'):
|
||||
face.normal = (v2 - v1).cross(v3 - v1)
|
||||
face.normal.normalize()
|
||||
glNormal3f(face.normal.x, face.normal.y, face.normal.z)
|
||||
glVertex3f(v1.x, v1.y, v1.z)
|
||||
glVertex3f(v2.x, v2.y, v2.z)
|
||||
glVertex3f(v3.x, v3.y, v3.z)
|
||||
@ -378,13 +386,20 @@ class PreviewGLCanvas(GLCanvas):
|
||||
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
gluPerspective(90.0, float(self.GetSize().GetWidth()) / float(self.GetSize().GetHeight()), 1.0, 1000.0)
|
||||
aspect = float(self.GetSize().GetWidth()) / float(self.GetSize().GetHeight())
|
||||
if self.view3D:
|
||||
gluPerspective(90.0, aspect, 1.0, 1000.0)
|
||||
else:
|
||||
glOrtho(-self.zoom * aspect, self.zoom * aspect, -self.zoom, self.zoom, -1000.0, 1000.0)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
glTranslate(0,0,-self.zoom)
|
||||
glRotate(-self.pitch, 1,0,0)
|
||||
glRotate(self.yaw, 0,0,1)
|
||||
if self.parent.triangleMesh != None:
|
||||
glTranslate(0,0,-self.parent.triangleMesh.getCarveCornerMaximum().z / 2)
|
||||
return
|
||||
if self.view3D:
|
||||
glTranslate(0,0,-self.zoom)
|
||||
glRotate(-self.pitch, 1,0,0)
|
||||
glRotate(self.yaw, 0,0,1)
|
||||
if self.parent.triangleMesh != None:
|
||||
glTranslate(0,0,-self.parent.triangleMesh.getCarveCornerMaximum().z / 2)
|
||||
else:
|
||||
glTranslate(self.offsetX, self.offsetY, 0)
|
||||
|
||||
|
@ -1,404 +0,0 @@
|
||||
"""
|
||||
This page is in the table of contents.
|
||||
Statistic is an extremely valuable analyze plugin to print and/or save the statistics of the generated gcode.
|
||||
|
||||
The statistic manual page is at:
|
||||
http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Statistic
|
||||
|
||||
==Operation==
|
||||
The default 'Activate Statistic' checkbox is on. When it is on, the functions described below will work when called from the skeinforge toolchain, when it is off, the functions will not be called from the toolchain. The functions will still be called, whether or not the 'Activate Statistic' checkbox is on, when statistic is run directly.
|
||||
|
||||
==Settings==
|
||||
===Extrusion Diameter over Thickness===
|
||||
Default is 1.25.
|
||||
|
||||
The 'Extrusion Diameter over Thickness is the ratio of the extrusion diameter over the layer height, the default is 1.25. The extrusion fill density ratio that is printed to the console, ( it is derived quantity not a parameter ) is the area of the extrusion diameter over the extrusion width over the layer height. Assuming the extrusion diameter is correct, a high value means the filament will be packed tightly, and the object will be almost as dense as the filament. If the fill density ratio is too high, there could be too little room for the filament, and the extruder will end up plowing through the extra filament. A low fill density ratio means the filaments will be far away from each other, the object will be leaky and light. The fill density ratio with the default extrusion settings is around 0.68.
|
||||
|
||||
===Print Statistics===
|
||||
Default is on.
|
||||
|
||||
When the 'Print Statistics' checkbox is on, the statistics will be printed to the console.
|
||||
|
||||
===Save Statistics===
|
||||
Default is off.
|
||||
|
||||
When the 'Save Statistics' checkbox is on, the statistics will be saved as a .txt file.
|
||||
|
||||
==Gcodes==
|
||||
An explanation of the gcodes is at:
|
||||
http://reprap.org/bin/view/Main/Arduino_GCode_Interpreter
|
||||
|
||||
and at:
|
||||
http://reprap.org/bin/view/Main/MCodeReference
|
||||
|
||||
A gode example is at:
|
||||
http://forums.reprap.org/file.php?12,file=565
|
||||
|
||||
==Examples==
|
||||
Below are examples of statistic being used. These examples are run in a terminal in the folder which contains Screw Holder_penultimate.gcode and statistic.py. The 'Save Statistics' checkbox is selected.
|
||||
|
||||
> python statistic.py
|
||||
This brings up the statistic dialog.
|
||||
|
||||
> python statistic.py Screw Holder_penultimate.gcode
|
||||
Statistics are being generated for the file /home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/models/Screw Holder_penultimate.gcode
|
||||
|
||||
Cost
|
||||
Machine time cost is 0.31$.
|
||||
Material cost is 0.2$.
|
||||
Total cost is 0.51$.
|
||||
|
||||
Extent
|
||||
X axis extrusion starts at 61 mm and ends at 127 mm, for a width of 65 mm.
|
||||
Y axis extrusion starts at 81 mm and ends at 127 mm, for a depth of 45 mm.
|
||||
Z axis extrusion starts at 0 mm and ends at 15 mm, for a height of 15 mm.
|
||||
|
||||
Extruder
|
||||
Build time is 18 minutes 47 seconds.
|
||||
Distance extruded is 46558.4 mm.
|
||||
Distance traveled is 58503.3 mm.
|
||||
Extruder speed is 50.0
|
||||
Extruder was extruding 79.6 percent of the time.
|
||||
Extruder was toggled 1688 times.
|
||||
Operating flow rate is 9.8 mm3/s.
|
||||
Feed rate average is 51.9 mm/s, (3113.8 mm/min).
|
||||
|
||||
Filament
|
||||
Cross section area is 0.2 mm2.
|
||||
Extrusion diameter is 0.5 mm.
|
||||
Extrusion fill density ratio is 0.68
|
||||
|
||||
Material
|
||||
Mass extruded is 9.8 grams.
|
||||
Volume extruded is 9.1 cc.
|
||||
|
||||
Meta
|
||||
Text has 33738 lines and a size of 1239.0 KB.
|
||||
Version is 11.09.28
|
||||
|
||||
Procedures
|
||||
carve
|
||||
bottom
|
||||
preface
|
||||
inset
|
||||
fill
|
||||
multiply
|
||||
speed
|
||||
temperature
|
||||
raft
|
||||
skirt
|
||||
dimension
|
||||
bookend
|
||||
|
||||
Profile
|
||||
UM-PLA-HighQuality
|
||||
|
||||
Slice
|
||||
Edge width is 0.72 mm.
|
||||
Layer height is 0.4 mm.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
|
||||
import __init__
|
||||
|
||||
from fabmetheus_utilities.vector3 import Vector3
|
||||
from fabmetheus_utilities import archive
|
||||
from fabmetheus_utilities import euclidean
|
||||
from fabmetheus_utilities import gcodec
|
||||
from fabmetheus_utilities import settings
|
||||
from skeinforge_application.skeinforge_utilities import skeinforge_polyfile
|
||||
from skeinforge_application.skeinforge_utilities import skeinforge_profile
|
||||
import cStringIO
|
||||
import math
|
||||
import sys
|
||||
|
||||
|
||||
__author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
|
||||
__date__ = '$Date: 2008/21/04 $'
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
|
||||
|
||||
def getNewRepository():
|
||||
'Get new repository.'
|
||||
return StatisticRepository()
|
||||
|
||||
def getWindowAnalyzeFile(fileName):
|
||||
"Write statistics for a gcode file."
|
||||
return getWindowAnalyzeFileGivenText( fileName, archive.getFileText(fileName) )
|
||||
|
||||
def getWindowAnalyzeFileGivenText( fileName, gcodeText, repository=None):
|
||||
"Write statistics for a gcode file."
|
||||
print('')
|
||||
print('')
|
||||
print('Statistics are being generated for the file ' + archive.getSummarizedFileName(fileName) )
|
||||
if repository == None:
|
||||
repository = settings.getReadRepository( StatisticRepository() )
|
||||
skein = StatisticSkein()
|
||||
statisticGcode = skein.getCraftedGcode(gcodeText, repository)
|
||||
if repository.printStatistics.value:
|
||||
print(statisticGcode)
|
||||
if repository.saveStatistics.value:
|
||||
archive.writeFileMessageEnd('.txt', fileName, statisticGcode, 'The statistics file is saved as ')
|
||||
|
||||
def writeOutput(fileName, fileNamePenultimate, fileNameSuffix, filePenultimateWritten, gcodeText=''):
|
||||
"Write statistics for a skeinforge gcode file, if 'Write Statistics File for Skeinforge Chain' is selected."
|
||||
repository = settings.getReadRepository( StatisticRepository() )
|
||||
if gcodeText == '':
|
||||
gcodeText = archive.getFileText( fileNameSuffix )
|
||||
if repository.activateStatistic.value:
|
||||
getWindowAnalyzeFileGivenText( fileNameSuffix, gcodeText, repository )
|
||||
|
||||
|
||||
class StatisticRepository:
|
||||
"A class to handle the statistics settings."
|
||||
def __init__(self):
|
||||
"Set the default settings, execute title & settings fileName."
|
||||
skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_plugins.analyze_plugins.statistic.html', self)
|
||||
self.openWikiManualHelpPage = settings.HelpPage().getOpenFromAbsolute('http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Statistic')
|
||||
self.activateStatistic = settings.BooleanSetting().getFromValue('Activate Statistic', self, True )
|
||||
settings.LabelSeparator().getFromRepository(self)
|
||||
settings.LabelDisplay().getFromName('- Cost -', self )
|
||||
self.machineTime = settings.FloatSpin().getFromValue( 0.0, 'Machine Time ($/hour):', self, 5.0, 1.0 )
|
||||
self.material = settings.FloatSpin().getFromValue( 0.0, 'Material ($/kg):', self, 40.0, 20.0 )
|
||||
settings.LabelSeparator().getFromRepository(self)
|
||||
self.density = settings.FloatSpin().getFromValue( 500.0, 'Density (kg/m3):', self, 2000.0, 930.0 )
|
||||
self.extrusionDiameterOverThickness = settings.FloatSpin().getFromValue( 1.0, 'Extrusion Diameter over Thickness (ratio):', self, 1.5, 1.25 )
|
||||
self.fileNameInput = settings.FileNameInput().getFromFileName( [ ('Gcode text files', '*.gcode') ], 'Open File to Generate Statistics for', self, '')
|
||||
self.printStatistics = settings.BooleanSetting().getFromValue('Print Statistics', self, True )
|
||||
self.saveStatistics = settings.BooleanSetting().getFromValue('Save Statistics', self, False )
|
||||
self.executeTitle = 'Generate Statistics'
|
||||
|
||||
def execute(self):
|
||||
"Write button has been clicked."
|
||||
fileNames = skeinforge_polyfile.getFileOrGcodeDirectory( self.fileNameInput.value, self.fileNameInput.wasCancelled, ['_comment'] )
|
||||
for fileName in fileNames:
|
||||
getWindowAnalyzeFile(fileName)
|
||||
|
||||
|
||||
class StatisticSkein:
|
||||
"A class to get statistics for a gcode skein."
|
||||
def __init__(self):
|
||||
self.extrusionDiameter = None
|
||||
self.oldLocation = None
|
||||
self.operatingFeedRatePerSecond = None
|
||||
self.output = cStringIO.StringIO()
|
||||
self.profileName = None
|
||||
self.version = None
|
||||
|
||||
def addLine(self, line):
|
||||
"Add a line of text and a newline to the output."
|
||||
self.output.write(line + '\n')
|
||||
|
||||
def addToPath(self, location):
|
||||
"Add a point to travel and maybe extrusion."
|
||||
if self.oldLocation != None:
|
||||
travel = location.distance( self.oldLocation )
|
||||
if self.feedRateMinute > 0.0:
|
||||
self.totalBuildTime += 60.0 * travel / self.feedRateMinute
|
||||
self.totalDistanceTraveled += travel
|
||||
if self.extruderActive:
|
||||
self.totalDistanceExtruded += travel
|
||||
self.cornerMaximum.maximize(location)
|
||||
self.cornerMinimum.minimize(location)
|
||||
self.oldLocation = location
|
||||
|
||||
def extruderSet( self, active ):
|
||||
"Maybe increment the number of times the extruder was toggled."
|
||||
if self.extruderActive != active:
|
||||
self.extruderToggled += 1
|
||||
self.extruderActive = active
|
||||
|
||||
def getCraftedGcode(self, gcodeText, repository):
|
||||
"Parse gcode text and store the statistics."
|
||||
self.absoluteEdgeWidth = 0.4
|
||||
self.characters = 0
|
||||
self.cornerMaximum = Vector3(-987654321.0, -987654321.0, -987654321.0)
|
||||
self.cornerMinimum = Vector3(987654321.0, 987654321.0, 987654321.0)
|
||||
self.extruderActive = False
|
||||
self.extruderSpeed = None
|
||||
self.extruderToggled = 0
|
||||
self.feedRateMinute = 600.0
|
||||
self.layerHeight = 0.4
|
||||
self.numberOfLines = 0
|
||||
self.procedures = []
|
||||
self.repository = repository
|
||||
self.totalBuildTime = 0.0
|
||||
self.totalDistanceExtruded = 0.0
|
||||
self.totalDistanceTraveled = 0.0
|
||||
lines = archive.getTextLines(gcodeText)
|
||||
for line in lines:
|
||||
self.parseLine(line)
|
||||
averageFeedRate = self.totalDistanceTraveled / self.totalBuildTime
|
||||
self.characters += self.numberOfLines
|
||||
kilobytes = round( self.characters / 1024.0 )
|
||||
halfEdgeWidth = 0.5 * self.absoluteEdgeWidth
|
||||
halfExtrusionCorner = Vector3( halfEdgeWidth, halfEdgeWidth, halfEdgeWidth )
|
||||
self.cornerMaximum += halfExtrusionCorner
|
||||
self.cornerMinimum -= halfExtrusionCorner
|
||||
extent = self.cornerMaximum - self.cornerMinimum
|
||||
roundedHigh = euclidean.getRoundedPoint( self.cornerMaximum )
|
||||
roundedLow = euclidean.getRoundedPoint( self.cornerMinimum )
|
||||
roundedExtent = euclidean.getRoundedPoint( extent )
|
||||
axisString = " axis extrusion starts at "
|
||||
crossSectionArea = 0.9 * self.absoluteEdgeWidth * self.layerHeight # 0.9 if from the typical fill density
|
||||
if self.extrusionDiameter != None:
|
||||
crossSectionArea = math.pi / 4.0 * self.extrusionDiameter * self.extrusionDiameter
|
||||
volumeExtruded = 0.001 * crossSectionArea * self.totalDistanceExtruded
|
||||
mass = volumeExtruded / repository.density.value
|
||||
machineTimeCost = repository.machineTime.value * self.totalBuildTime / 3600.0
|
||||
materialCost = repository.material.value * mass
|
||||
self.addLine(' ')
|
||||
self.addLine('Cost')
|
||||
self.addLine( "Machine time cost is %s$." % round( machineTimeCost, 2 ) )
|
||||
self.addLine( "Material cost is %s$." % round( materialCost, 2 ) )
|
||||
self.addLine( "Total cost is %s$." % round( machineTimeCost + materialCost, 2 ) )
|
||||
self.addLine(' ')
|
||||
self.addLine('Extent')
|
||||
self.addLine( "X%s%s mm and ends at %s mm, for a width of %s mm." % ( axisString, int( roundedLow.x ), int( roundedHigh.x ), int( extent.x ) ) )
|
||||
self.addLine( "Y%s%s mm and ends at %s mm, for a depth of %s mm." % ( axisString, int( roundedLow.y ), int( roundedHigh.y ), int( extent.y ) ) )
|
||||
self.addLine( "Z%s%s mm and ends at %s mm, for a height of %s mm." % ( axisString, int( roundedLow.z ), int( roundedHigh.z ), int( extent.z ) ) )
|
||||
self.addLine(' ')
|
||||
self.addLine('Extruder')
|
||||
self.addLine( "Build time is %s." % euclidean.getDurationString( self.totalBuildTime ) )
|
||||
self.addLine( "Distance extruded is %s mm." % euclidean.getThreeSignificantFigures( self.totalDistanceExtruded ) )
|
||||
self.addLine( "Distance traveled is %s mm." % euclidean.getThreeSignificantFigures( self.totalDistanceTraveled ) )
|
||||
if self.extruderSpeed != None:
|
||||
self.addLine( "Extruder speed is %s" % euclidean.getThreeSignificantFigures( self.extruderSpeed ) )
|
||||
self.addLine( "Extruder was extruding %s percent of the time." % euclidean.getThreeSignificantFigures( 100.0 * self.totalDistanceExtruded / self.totalDistanceTraveled ) )
|
||||
self.addLine( "Extruder was toggled %s times." % self.extruderToggled )
|
||||
if self.operatingFeedRatePerSecond != None:
|
||||
flowRate = crossSectionArea * self.operatingFeedRatePerSecond
|
||||
self.addLine( "Operating flow rate is %s mm3/s." % euclidean.getThreeSignificantFigures( flowRate ) )
|
||||
self.addLine( "Feed rate average is %s mm/s, (%s mm/min)." % ( euclidean.getThreeSignificantFigures( averageFeedRate ), euclidean.getThreeSignificantFigures( 60.0 * averageFeedRate ) ) )
|
||||
self.addLine(' ')
|
||||
self.addLine('Filament')
|
||||
self.addLine( "Cross section area is %s mm2." % euclidean.getThreeSignificantFigures( crossSectionArea ) )
|
||||
if self.extrusionDiameter != None:
|
||||
self.addLine( "Extrusion diameter is %s mm." % euclidean.getThreeSignificantFigures( self.extrusionDiameter ) )
|
||||
self.addLine('Extrusion fill density ratio is %s' % euclidean.getThreeSignificantFigures( crossSectionArea / self.absoluteEdgeWidth / self.layerHeight ) )
|
||||
self.addLine(' ')
|
||||
self.addLine('Material')
|
||||
self.addLine( "Mass extruded is %s grams." % euclidean.getThreeSignificantFigures( 1000.0 * mass ) )
|
||||
self.addLine( "Volume extruded is %s cc." % euclidean.getThreeSignificantFigures( volumeExtruded ) )
|
||||
self.addLine(' ')
|
||||
self.addLine('Meta')
|
||||
self.addLine( "Text has %s lines and a size of %s KB." % ( self.numberOfLines, kilobytes ) )
|
||||
if self.version != None:
|
||||
self.addLine( "Version is " + self.version )
|
||||
self.addLine(' ')
|
||||
self.addLine( "Procedures" )
|
||||
for procedure in self.procedures:
|
||||
self.addLine(procedure)
|
||||
if self.profileName != None:
|
||||
self.addLine(' ')
|
||||
self.addLine( 'Profile' )
|
||||
self.addLine(self.profileName)
|
||||
self.addLine(' ')
|
||||
self.addLine('Slice')
|
||||
self.addLine( "Edge width is %s mm." % euclidean.getThreeSignificantFigures( self.absoluteEdgeWidth ) )
|
||||
self.addLine( "Layer height is %s mm." % euclidean.getThreeSignificantFigures( self.layerHeight ) )
|
||||
self.addLine(' ')
|
||||
return self.output.getvalue()
|
||||
|
||||
def getLocationSetFeedRateToSplitLine( self, splitLine ):
|
||||
"Get location ans set feed rate to the plsit line."
|
||||
location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine)
|
||||
indexOfF = gcodec.getIndexOfStartingWithSecond( "F", splitLine )
|
||||
if indexOfF > 0:
|
||||
self.feedRateMinute = gcodec.getDoubleAfterFirstLetter( splitLine[indexOfF] )
|
||||
return location
|
||||
|
||||
def helicalMove( self, isCounterclockwise, splitLine ):
|
||||
"Get statistics for a helical move."
|
||||
if self.oldLocation == None:
|
||||
return
|
||||
location = self.getLocationSetFeedRateToSplitLine(splitLine)
|
||||
location += self.oldLocation
|
||||
center = self.oldLocation.copy()
|
||||
indexOfR = gcodec.getIndexOfStartingWithSecond( "R", splitLine )
|
||||
if indexOfR > 0:
|
||||
radius = gcodec.getDoubleAfterFirstLetter( splitLine[ indexOfR ] )
|
||||
halfLocationMinusOld = location - self.oldLocation
|
||||
halfLocationMinusOld *= 0.5
|
||||
halfLocationMinusOldLength = halfLocationMinusOld.magnitude()
|
||||
centerMidpointDistanceSquared = radius * radius - halfLocationMinusOldLength * halfLocationMinusOldLength
|
||||
centerMidpointDistance = math.sqrt( max( centerMidpointDistanceSquared, 0.0 ) )
|
||||
centerMinusMidpoint = euclidean.getRotatedWiddershinsQuarterAroundZAxis( halfLocationMinusOld )
|
||||
centerMinusMidpoint.normalize()
|
||||
centerMinusMidpoint *= centerMidpointDistance
|
||||
if isCounterclockwise:
|
||||
center.setToVector3( halfLocationMinusOld + centerMinusMidpoint )
|
||||
else:
|
||||
center.setToVector3( halfLocationMinusOld - centerMinusMidpoint )
|
||||
else:
|
||||
center.x = gcodec.getDoubleForLetter( "I", splitLine )
|
||||
center.y = gcodec.getDoubleForLetter( "J", splitLine )
|
||||
curveSection = 0.5
|
||||
center += self.oldLocation
|
||||
afterCenterSegment = location - center
|
||||
beforeCenterSegment = self.oldLocation - center
|
||||
afterCenterDifferenceAngle = euclidean.getAngleAroundZAxisDifference( afterCenterSegment, beforeCenterSegment )
|
||||
absoluteDifferenceAngle = abs( afterCenterDifferenceAngle )
|
||||
steps = int( round( 0.5 + max( absoluteDifferenceAngle * 2.4, absoluteDifferenceAngle * beforeCenterSegment.magnitude() / curveSection ) ) )
|
||||
stepPlaneAngle = euclidean.getWiddershinsUnitPolar( afterCenterDifferenceAngle / steps )
|
||||
zIncrement = ( afterCenterSegment.z - beforeCenterSegment.z ) / float( steps )
|
||||
for step in xrange( 1, steps ):
|
||||
beforeCenterSegment = euclidean.getRoundZAxisByPlaneAngle( stepPlaneAngle, beforeCenterSegment )
|
||||
beforeCenterSegment.z += zIncrement
|
||||
arcPoint = center + beforeCenterSegment
|
||||
self.addToPath( arcPoint )
|
||||
self.addToPath( location )
|
||||
|
||||
def linearMove( self, splitLine ):
|
||||
"Get statistics for a linear move."
|
||||
location = self.getLocationSetFeedRateToSplitLine(splitLine)
|
||||
self.addToPath( location )
|
||||
|
||||
def parseLine(self, line):
|
||||
"Parse a gcode line and add it to the statistics."
|
||||
self.characters += len(line)
|
||||
self.numberOfLines += 1
|
||||
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
|
||||
if len(splitLine) < 1:
|
||||
return
|
||||
firstWord = splitLine[0]
|
||||
if firstWord == 'G1':
|
||||
self.linearMove(splitLine)
|
||||
elif firstWord == 'G2':
|
||||
self.helicalMove( False, splitLine )
|
||||
elif firstWord == 'G3':
|
||||
self.helicalMove( True, splitLine )
|
||||
elif firstWord == 'M101':
|
||||
self.extruderSet( True )
|
||||
elif firstWord == 'M102':
|
||||
self.extruderSet( False )
|
||||
elif firstWord == 'M103':
|
||||
self.extruderSet( False )
|
||||
elif firstWord == 'M108':
|
||||
self.extruderSpeed = gcodec.getDoubleAfterFirstLetter(splitLine[1])
|
||||
elif firstWord == '(<layerHeight>':
|
||||
self.layerHeight = float(splitLine[1])
|
||||
self.extrusionDiameter = self.repository.extrusionDiameterOverThickness.value * self.layerHeight
|
||||
elif firstWord == '(<operatingFeedRatePerSecond>':
|
||||
self.operatingFeedRatePerSecond = float(splitLine[1])
|
||||
elif firstWord == '(<edgeWidth>':
|
||||
self.absoluteEdgeWidth = abs(float(splitLine[1]))
|
||||
elif firstWord == '(<procedureName>':
|
||||
self.procedures.append(splitLine[1])
|
||||
elif firstWord == '(<profileName>':
|
||||
self.profileName = line.replace('(<profileName>', '').replace('</profileName>)', '').strip()
|
||||
elif firstWord == '(<version>':
|
||||
self.version = splitLine[1]
|
||||
|
||||
|
||||
def main():
|
||||
"Display the statistics dialog."
|
||||
if len(sys.argv) > 1:
|
||||
getWindowAnalyzeFile(' '.join(sys.argv[1 :]))
|
||||
else:
|
||||
settings.startMainLoopFromConstructor(getNewRepository())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,359 +0,0 @@
|
||||
"""
|
||||
This page is in the table of contents.
|
||||
Vectorwrite is a very interesting analyze plugin that will create an SVG vector image for each layer that you can then use in some other printing system.
|
||||
|
||||
The Scalable Vector Graphics file can be opened by an SVG viewer or an SVG capable browser like Mozilla:
|
||||
http://www.mozilla.com/firefox/
|
||||
|
||||
The vectorwrite manual page is at:
|
||||
http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Vectorwrite
|
||||
|
||||
==Operation==
|
||||
The default 'Activate Vectorwrite' checkbox is off. When it is on, the functions described below will work when called from the skeinforge toolchain, when it is off, the functions will not be called from the toolchain. The functions will still be called, whether or not the 'Activate Vectorwrite' checkbox is on, when vectorwrite is run directly.
|
||||
|
||||
==Settings==
|
||||
===Add Loops===
|
||||
Default is on.
|
||||
|
||||
If 'Add Loops' is selected, the loops will be added in yellow to the the scalable vector graphics output.
|
||||
|
||||
===Add Paths===
|
||||
Default is on.
|
||||
|
||||
If 'Add Paths' is selected, the paths will be added in pink to the the scalable vector graphics output.
|
||||
|
||||
===Add Perimeters===
|
||||
Default is on.
|
||||
|
||||
If 'Add Perimeters' is selected, the edges will be added to the the scalable vector graphics output. The outer edges will be red and the inner edges will be orange.
|
||||
|
||||
===Layers===
|
||||
====Layers From====
|
||||
Default is zero.
|
||||
|
||||
The "Layers From" is the index of the bottom layer that will be displayed. If the layer from is the default zero, the display will start from the lowest layer. If the the layer from index is negative, then the display will start from the layer from index below the top layer.
|
||||
|
||||
====Layers To====
|
||||
Default is a huge number, which will be limited to the highest index layer.
|
||||
|
||||
The "Layers To" is the index of the top layer that will be displayed. If the layer to index is a huge number like the default, the display will go to the top of the model, at least until we model habitats:) If the layer to index is negative, then the display will go to the layer to index below the top layer. The layer from until layer to index is a python slice.
|
||||
|
||||
===SVG Viewer===
|
||||
Default is webbrowser.
|
||||
|
||||
If the 'SVG Viewer' is set to the default 'webbrowser', the scalable vector graphics file will be sent to the default browser to be opened. If the 'SVG Viewer' is set to a program name, the scalable vector graphics file will be sent to that program to be opened.
|
||||
|
||||
==Examples==
|
||||
Below are examples of vectorwrite being used. These examples are run in a terminal in the folder which contains Screw Holder_penultimate.gcode and vectorwrite.py.
|
||||
|
||||
> python vectorwrite.py
|
||||
This brings up the vectorwrite dialog.
|
||||
|
||||
> python vectorwrite.py Screw Holder_penultimate.gcode
|
||||
The vectorwrite file is saved as Screw_Holder_penultimate_vectorwrite.svg
|
||||
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
|
||||
import __init__
|
||||
|
||||
from fabmetheus_utilities.vector3 import Vector3
|
||||
from fabmetheus_utilities import archive
|
||||
from fabmetheus_utilities import euclidean
|
||||
from fabmetheus_utilities import gcodec
|
||||
from fabmetheus_utilities import settings
|
||||
from fabmetheus_utilities import svg_writer
|
||||
from skeinforge_application.skeinforge_utilities import skeinforge_polyfile
|
||||
from skeinforge_application.skeinforge_utilities import skeinforge_profile
|
||||
import cStringIO
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
__author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
|
||||
__credits__ = 'Nophead <http://hydraraptor.blogspot.com/>'
|
||||
__date__ = '$Date: 2008/21/04 $'
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
|
||||
|
||||
def getNewRepository():
|
||||
'Get new repository.'
|
||||
return VectorwriteRepository()
|
||||
|
||||
def getWindowAnalyzeFile(fileName):
|
||||
'Write scalable vector graphics for a gcode file.'
|
||||
gcodeText = archive.getFileText(fileName)
|
||||
return getWindowAnalyzeFileGivenText(fileName, gcodeText)
|
||||
|
||||
def getWindowAnalyzeFileGivenText( fileName, gcodeText, repository=None):
|
||||
'Write scalable vector graphics for a gcode file given the settings.'
|
||||
if gcodeText == '':
|
||||
return None
|
||||
if repository == None:
|
||||
repository = settings.getReadRepository( VectorwriteRepository() )
|
||||
startTime = time.time()
|
||||
vectorwriteGcode = VectorwriteSkein().getCarvedSVG( fileName, gcodeText, repository )
|
||||
if vectorwriteGcode == '':
|
||||
return None
|
||||
suffixFileName = fileName[ : fileName.rfind('.') ] + '_vectorwrite.svg'
|
||||
suffixDirectoryName = os.path.dirname(suffixFileName)
|
||||
suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_')
|
||||
suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName )
|
||||
archive.writeFileText( suffixFileName, vectorwriteGcode )
|
||||
print('The vectorwrite file is saved as ' + archive.getSummarizedFileName(suffixFileName) )
|
||||
print('It took %s to vectorwrite the file.' % euclidean.getDurationString( time.time() - startTime ) )
|
||||
settings.openSVGPage( suffixFileName, repository.svgViewer.value )
|
||||
|
||||
def writeOutput(fileName, fileNamePenultimate, fileNameSuffix, filePenultimateWritten, gcodeText=''):
|
||||
'Write scalable vector graphics for a skeinforge gcode file, if activate vectorwrite is selected.'
|
||||
repository = settings.getReadRepository( VectorwriteRepository() )
|
||||
if not repository.activateVectorwrite.value:
|
||||
return
|
||||
gcodeText = archive.getTextIfEmpty( fileNameSuffix, gcodeText )
|
||||
getWindowAnalyzeFileGivenText( fileNameSuffix, gcodeText, repository )
|
||||
|
||||
|
||||
class SVGWriterVectorwrite( svg_writer.SVGWriter ):
|
||||
'A class to vectorwrite a carving.'
|
||||
def addPaths( self, colorName, paths, transformString ):
|
||||
'Add paths to the output.'
|
||||
pathString = ''
|
||||
for path in paths:
|
||||
pathString += self.getSVGStringForPath(path) + ' '
|
||||
if len( pathString ) < 1:
|
||||
return
|
||||
pathElementNodeCopy = self.pathElementNode.getCopy('', self.pathElementNode.parentNode )
|
||||
pathCopyDictionary = pathElementNodeCopy.attributes
|
||||
pathCopyDictionary['d'] = pathString[ : - 1 ]
|
||||
pathCopyDictionary['fill'] = 'none'
|
||||
pathCopyDictionary['stroke'] = colorName
|
||||
pathCopyDictionary['transform'] = transformString
|
||||
|
||||
def addLoopLayerToOutput( self, layerIndex, threadLayer ):
|
||||
'Add rotated boundary layer to the output.'
|
||||
settings.printProgress(self.layerIndex, 'vectorwrite')
|
||||
self.addLayerBegin( layerIndex, threadLayer )
|
||||
transformString = self.getTransformString()
|
||||
self.pathDictionary['d'] = self.getSVGStringForLoops( threadLayer.boundaryLoops )
|
||||
self.pathDictionary['transform'] = transformString
|
||||
self.addPaths('#fa0', threadLayer.innerPerimeters, transformString ) #orange
|
||||
self.addPaths('#ff0', threadLayer.loops, transformString ) #yellow
|
||||
self.addPaths('#f00', threadLayer.outerPerimeters, transformString ) #red
|
||||
self.addPaths('#f5c', threadLayer.paths, transformString ) #light violetred
|
||||
|
||||
|
||||
class ThreadLayer:
|
||||
'Threads with a z.'
|
||||
def __init__( self, z ):
|
||||
self.boundaryLoops = []
|
||||
self.innerPerimeters = []
|
||||
self.loops = []
|
||||
self.outerPerimeters = []
|
||||
self.paths = []
|
||||
self.z = z
|
||||
|
||||
def __repr__(self):
|
||||
'Get the string representation of this loop layer.'
|
||||
return str(self.__dict__)
|
||||
|
||||
def getTotalNumberOfThreads(self):
|
||||
'Get the total number of loops, paths and edges.'
|
||||
return len(self.boundaryLoops) + len(self.innerPerimeters) + len(self.loops) + len(self.outerPerimeters) + len(self.paths)
|
||||
|
||||
def maximize(self, vector3):
|
||||
'Maximize the vector3 over the loops, paths and edges.'
|
||||
pointComplex = vector3.dropAxis()
|
||||
pointComplex = euclidean.getMaximum(euclidean.getMaximumByComplexPaths(self.boundaryLoops), pointComplex)
|
||||
pointComplex = euclidean.getMaximum(euclidean.getMaximumByComplexPaths(self.innerPerimeters), pointComplex)
|
||||
pointComplex = euclidean.getMaximum(euclidean.getMaximumByComplexPaths(self.loops), pointComplex)
|
||||
pointComplex = euclidean.getMaximum(euclidean.getMaximumByComplexPaths(self.outerPerimeters), pointComplex)
|
||||
pointComplex = euclidean.getMaximum(euclidean.getMaximumByComplexPaths(self.paths), pointComplex)
|
||||
vector3.setToXYZ(pointComplex.real, pointComplex.imag, max(self.z, vector3.z))
|
||||
|
||||
def minimize(self, vector3):
|
||||
'Minimize the vector3 over the loops, paths and edges.'
|
||||
pointComplex = vector3.dropAxis()
|
||||
pointComplex = euclidean.getMinimum(euclidean.getMinimumByComplexPaths(self.boundaryLoops), pointComplex)
|
||||
pointComplex = euclidean.getMinimum(euclidean.getMinimumByComplexPaths(self.innerPerimeters), pointComplex)
|
||||
pointComplex = euclidean.getMinimum(euclidean.getMinimumByComplexPaths(self.loops), pointComplex)
|
||||
pointComplex = euclidean.getMinimum(euclidean.getMinimumByComplexPaths(self.outerPerimeters), pointComplex)
|
||||
pointComplex = euclidean.getMinimum(euclidean.getMinimumByComplexPaths(self.paths), pointComplex)
|
||||
vector3.setToXYZ(pointComplex.real, pointComplex.imag, min(self.z, vector3.z))
|
||||
|
||||
|
||||
class VectorwriteRepository:
|
||||
'A class to handle the vectorwrite settings.'
|
||||
def __init__(self):
|
||||
'Set the default settings, execute title & settings fileName.'
|
||||
skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_plugins.analyze_plugins.vectorwrite.html', self )
|
||||
self.activateVectorwrite = settings.BooleanSetting().getFromValue('Activate Vectorwrite', self, False )
|
||||
self.fileNameInput = settings.FileNameInput().getFromFileName( [ ('Gcode text files', '*.gcode') ], 'Open File to Write Vector Graphics for', self, '')
|
||||
self.openWikiManualHelpPage = settings.HelpPage().getOpenFromAbsolute('http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Vectorwrite')
|
||||
self.addLoops = settings.BooleanSetting().getFromValue('Add Loops', self, True)
|
||||
self.addPaths = settings.BooleanSetting().getFromValue('Add Paths', self, True)
|
||||
self.addPerimeters = settings.BooleanSetting().getFromValue('Add Perimeters', self, True)
|
||||
settings.LabelSeparator().getFromRepository(self)
|
||||
settings.LabelDisplay().getFromName('- Layers -', self )
|
||||
self.layersFrom = settings.IntSpin().getFromValue( 0, 'Layers From (index):', self, 20, 0 )
|
||||
self.layersTo = settings.IntSpin().getSingleIncrementFromValue( 0, 'Layers To (index):', self, 912345678, 912345678 )
|
||||
settings.LabelSeparator().getFromRepository(self)
|
||||
self.svgViewer = settings.StringSetting().getFromValue('SVG Viewer:', self, 'webbrowser')
|
||||
settings.LabelSeparator().getFromRepository(self)
|
||||
self.executeTitle = 'Vectorwrite'
|
||||
|
||||
def execute(self):
|
||||
'Write button has been clicked.'
|
||||
fileNames = skeinforge_polyfile.getFileOrGcodeDirectory( self.fileNameInput.value, self.fileNameInput.wasCancelled )
|
||||
for fileName in fileNames:
|
||||
getWindowAnalyzeFile(fileName)
|
||||
|
||||
|
||||
class VectorwriteSkein:
|
||||
'A class to vectorwrite a carving.'
|
||||
def __init__(self):
|
||||
'Initialize.'
|
||||
self.layerCount = settings.LayerCount()
|
||||
|
||||
def addLoopLayer(self, z):
|
||||
'Add loop layer.'
|
||||
self.layerCount.printProgressIncrement('vectorwrite')
|
||||
self.threadLayer = ThreadLayer(z)
|
||||
self.threadLayers.append(self.threadLayer)
|
||||
|
||||
def addToLoops(self):
|
||||
'Add the thread to the loops.'
|
||||
self.isLoop = False
|
||||
if len(self.thread) < 1:
|
||||
return
|
||||
if self.repository.addLoops.value:
|
||||
self.threadLayer.loops.append(self.thread)
|
||||
self.thread = []
|
||||
|
||||
def addToPerimeters(self):
|
||||
'Add the thread to the edges.'
|
||||
self.isEdge = False
|
||||
if len(self.thread) < 1:
|
||||
return
|
||||
if self.repository.addPerimeters.value:
|
||||
if self.isOuter:
|
||||
self.threadLayer.outerPerimeters.append(self.thread)
|
||||
else:
|
||||
self.threadLayer.innerPerimeters.append(self.thread)
|
||||
self.thread = []
|
||||
|
||||
def getCarvedSVG(self, fileName, gcodeText, repository):
|
||||
'Parse gnu triangulated surface text and store the vectorwrite gcode.'
|
||||
cornerMaximum = Vector3(-987654321.0, -987654321.0, -987654321.0)
|
||||
cornerMinimum = Vector3(987654321.0, 987654321.0, 987654321.0)
|
||||
self.boundaryLoop = None
|
||||
self.extruderActive = False
|
||||
self.isEdge = False
|
||||
self.isLoop = False
|
||||
self.isOuter = False
|
||||
self.lines = archive.getTextLines(gcodeText)
|
||||
self.oldLocation = None
|
||||
self.thread = []
|
||||
self.threadLayers = []
|
||||
self.repository = repository
|
||||
self.parseInitialization()
|
||||
for line in self.lines[self.lineIndex :]:
|
||||
self.parseLine(line)
|
||||
self.removeEmptyLayers()
|
||||
for threadLayer in self.threadLayers:
|
||||
threadLayer.maximize(cornerMaximum)
|
||||
threadLayer.minimize(cornerMinimum)
|
||||
halfLayerThickness = 0.5 * self.layerHeight
|
||||
cornerMaximum.z += halfLayerThickness
|
||||
cornerMinimum.z -= halfLayerThickness
|
||||
svgWriter = SVGWriterVectorwrite(
|
||||
True, cornerMaximum, cornerMinimum, self.decimalPlacesCarried, self.layerHeight, self.edgeWidth)
|
||||
return svgWriter.getReplacedSVGTemplate(fileName, 'vectorwrite', self.threadLayers)
|
||||
|
||||
def getCarveLayerHeight(self):
|
||||
'Get the layer height.'
|
||||
return self.layerHeight
|
||||
|
||||
def linearMove( self, splitLine ):
|
||||
'Get statistics for a linear move.'
|
||||
location = gcodec.getLocationFromSplitLine(self.oldLocation, splitLine)
|
||||
if self.extruderActive:
|
||||
if len(self.thread) == 0:
|
||||
self.thread = [ self.oldLocation.dropAxis() ]
|
||||
self.thread.append(location.dropAxis())
|
||||
self.oldLocation = location
|
||||
|
||||
def parseInitialization(self):
|
||||
'Parse gcode initialization and store the parameters.'
|
||||
for self.lineIndex in xrange(len(self.lines)):
|
||||
line = self.lines[self.lineIndex]
|
||||
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
|
||||
firstWord = gcodec.getFirstWord(splitLine)
|
||||
if firstWord == '(<decimalPlacesCarried>':
|
||||
self.decimalPlacesCarried = int(splitLine[1])
|
||||
elif firstWord == '(<layerHeight>':
|
||||
self.layerHeight = float(splitLine[1])
|
||||
elif firstWord == '(<crafting>)':
|
||||
return
|
||||
elif firstWord == '(<edgeWidth>':
|
||||
self.edgeWidth = float(splitLine[1])
|
||||
|
||||
def parseLine(self, line):
|
||||
'Parse a gcode line and add it to the outset skein.'
|
||||
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
|
||||
if len(splitLine) < 1:
|
||||
return
|
||||
firstWord = splitLine[0]
|
||||
if firstWord == 'G1':
|
||||
self.linearMove(splitLine)
|
||||
elif firstWord == 'M101':
|
||||
self.extruderActive = True
|
||||
elif firstWord == 'M103':
|
||||
self.extruderActive = False
|
||||
if self.isLoop:
|
||||
self.addToLoops()
|
||||
return
|
||||
if self.isEdge:
|
||||
self.addToPerimeters()
|
||||
return
|
||||
if self.repository.addPaths.value:
|
||||
self.threadLayer.paths.append(self.thread)
|
||||
self.thread = []
|
||||
elif firstWord == '(</boundaryPerimeter>)':
|
||||
self.boundaryLoop = None
|
||||
elif firstWord == '(<boundaryPoint>':
|
||||
location = gcodec.getLocationFromSplitLine(None, splitLine)
|
||||
if self.boundaryLoop == None:
|
||||
self.boundaryLoop = []
|
||||
self.threadLayer.boundaryLoops.append( self.boundaryLoop )
|
||||
self.boundaryLoop.append(location.dropAxis())
|
||||
elif firstWord == '(<layer>':
|
||||
self.addLoopLayer(float(splitLine[1]))
|
||||
elif firstWord == '(</loop>)':
|
||||
self.addToLoops()
|
||||
elif firstWord == '(<loop>':
|
||||
self.isLoop = True
|
||||
elif firstWord == '(<edge>':
|
||||
self.isEdge = True
|
||||
self.isOuter = ( splitLine[1] == 'outer')
|
||||
elif firstWord == '(</edge>)':
|
||||
self.addToPerimeters()
|
||||
|
||||
def removeEmptyLayers(self):
|
||||
'Remove empty layers.'
|
||||
for threadLayerIndex, threadLayer in enumerate(self.threadLayers):
|
||||
if threadLayer.getTotalNumberOfThreads() > 0:
|
||||
self.threadLayers = self.threadLayers[threadLayerIndex :]
|
||||
return
|
||||
|
||||
|
||||
def main():
|
||||
'Display the vectorwrite dialog.'
|
||||
if len(sys.argv) > 1:
|
||||
getWindowAnalyzeFile(' '.join(sys.argv[1 :]))
|
||||
else:
|
||||
settings.startMainLoopFromConstructor(getNewRepository())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -125,3 +125,4 @@ class GcodeSmallSkein:
|
||||
self.output.write(';TYPE:FILL\n');
|
||||
elif line.startswith('(<alteration>'):
|
||||
self.output.write(';TYPE:CUSTOM\n');
|
||||
|
||||
|
@ -102,7 +102,7 @@ class JorisSkein:
|
||||
self.oldLocation = None
|
||||
|
||||
def getCraftedGcode( self, gcodeText, repository ):
|
||||
'Parse gcode text and store the skin gcode.'
|
||||
'Parse gcode text and store the joris gcode.'
|
||||
self.lines = archive.getTextLines(gcodeText)
|
||||
self.repository = repository
|
||||
self.layersFromBottom = repository.layersFrom.value
|
||||
@ -122,7 +122,7 @@ class JorisSkein:
|
||||
if firstWord == '(<layerThickness>':
|
||||
self.layerThickness = float(splitLine[1])
|
||||
elif firstWord == '(</extruderInitialization>)':
|
||||
self.distanceFeedRate.addTagBracketedProcedure('skin')
|
||||
self.distanceFeedRate.addTagBracketedProcedure('joris')
|
||||
return
|
||||
elif firstWord == '(<travelFeedRatePerSecond>':
|
||||
self.travelFeedRateMinute = 60.0 * float(splitLine[1])
|
||||
@ -176,14 +176,3 @@ class JorisSkein:
|
||||
self.distanceFeedRate.addLine('M103') # Turn extruder off.
|
||||
self.perimeter = None
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
'Display the skin dialog.'
|
||||
if len(sys.argv) > 1:
|
||||
writeOutput(' '.join(sys.argv[1 :]))
|
||||
else:
|
||||
settings.startMainLoopFromConstructor(getNewRepository())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
2
build.sh
2
build.sh
@ -109,7 +109,7 @@ if [ $BUILD_TARGET = "win32" ]; then
|
||||
rm -rf ${TARGET_DIR}/python/PyScripter.*
|
||||
rm -rf ${TARGET_DIR}/python/Doc
|
||||
rm -rf ${TARGET_DIR}/python/locale
|
||||
#rm -rf ${TARGET_DIR}/python/tcl
|
||||
rm -rf ${TARGET_DIR}/python/tcl
|
||||
rm -rf ${TARGET_DIR}/python/Lib/test
|
||||
rm -rf ${TARGET_DIR}/python/Lib/distutils
|
||||
rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
|
||||
|
Loading…
x
Reference in New Issue
Block a user