Commit eae708ee authored by Julian Stirling's avatar Julian Stirling 🐧

Class: Thing created, this is the full 3D object

parent 0d8a627e
......@@ -5,3 +5,6 @@ __pycache__
.ipynb_checkpoints
*.gcode
.directory
This diff is collapsed.
from .swomppy import version
from .swomppy import Params
from .swomppy import tol
from .machinecode import thingfromfile
from .machinecode import thingfromshells
from .machinecode import Thing
from .machinecode import Layer
from .machinecode import PrintSettings
from .machinecode import PrintPath
......
......@@ -26,8 +26,8 @@ def showlayer(layer):
print_plot.stroke(layer.fillPaths.as_normpath(),[pyx.color.rgb.red, pyx.style.linewidth(0.3)])
showsvg(print_plot)
def interactiveview(layers):
def interactiveview(thing):
def showing(n):
showlayer(layers[n])
int_view = interactive(showing,n=widgets.IntSlider(min=-0,max=len(layers)-1,step=1,value=10))
showlayer(thing.layers[n])
int_view = interactive(showing,n=widgets.IntSlider(min=-0,max=len(thing.layers)-1,step=1,value=10))
display(int_view)
......@@ -5,6 +5,59 @@ import operator
from .spaths import spath,spathlist,sline,scurve
from .swomppy import tol,pdist,Params,version
def thingfromfile(filename,printsettings=None):
if printsettings is None:
printsettings = PrintSettings()
else:
assert type(printsettings) is PrintSettings, 'printsettings must be a PrintSettings object'
print("I wish I did this. I will soon.")
return None
def thingfromshells(shells,printsettings=None):
if printsettings is None:
printsettings = PrintSettings()
else:
assert type(printsettings) is PrintSettings, 'printsettings must be a PrintSettings object'
N_lay = len(shells)
layers = []
for n,shell in enumerate(shells):
if n==0:
if printsettings.brim:
brim_layer=True
else:
brim_layer=False
else:
brim_layer=False
if n==0 or n==N_lay-1:
infillType=Params.VertInfill
infillSpacing=printsettings.offset
elif n==1 or n==N_lay-2:
infillType=Params.HorInfill
infillSpacing=printsettings.offset
else:
infillType=Params.CrossInfill
infillSpacing=3
layer = Layer(shell,offset=printsettings.offset,infillSpacing=infillSpacing,infillType=infillType,brim=brim_layer)
layer.fillLayer()
layers.append(layer)
return Thing(layers,printsettings)
class Thing(object):
"""A thing is a set of layers, and layers are a set of spaths"""
def __init__(self,layers,printsettings=None):
if printsettings is None:
printsettings = PrintSettings()
else:
assert type(printsettings) is PrintSettings, 'printsettings must be a PrintSettings object'
self.printsettings = printsettings
self.layers=layers
#Object for a layer, can do things like fill itself.
class Layer(object):
......@@ -234,11 +287,14 @@ class PrintPath():
class PrintSettings():
def __init__(self,flavor='Marlin', h0=.125, h=.25):
def __init__(self,flavor='Marlin', h0=.125, h=.25,offset=0.35,brim=True):
self.flavor = flavor
self.h0 = h0
self.h = h
self.offset = 0.35
self.brim=brim
assert flavor in CodeGen.acceptedFlavors, 'Unrecognised g-code flavor. Use %s'%str(CodeGen.acceptedFlavors)
if flavor=='UltiGCode':
self.fname_pre = 'sp_UM_'
......@@ -268,24 +324,23 @@ class PrintSettings():
def setMSpeed(self,ptype,speed):
self.MSpeed[ptype] = speed
def calcnumlayers(self, height):
return int((height-self.h0)//self.h)
def generateGcode(layers,name,printsettings=None,prependID=True):
if printsettings is None:
printsettings = PrintSettings()
else:
assert type(printsettings) is PrintSettings, 'printsettings must be a PrintSettings object'
def generateGcode(thing,name,prependID=True):
assert type(name) is str, 'Print name must be a string'
if prependID:
fname = printsettings.fname_pre+name+'.gcode'
fname = thing.printsettings.fname_pre+name+'.gcode'
else:
fname = name+'.gcode'
gfile = CodeGen(fname,flavor=printsettings.flavor)
gfile = CodeGen(fname,flavor=thing.printsettings.flavor)
gfile.writeHeader()
gfile.writeGcode(layers,printsettings)
gfile.writeGcode(thing)
gfile.writeFooter()
class CodeGen():
......@@ -367,7 +422,9 @@ M104 S0
;G-code OVER!'''%self.retract(),LineFeed=False)
self.flush()
def writeGcode(self,layers,printsettings):
def writeGcode(self,thing):
layers = thing.layers
printsettings = thing.printsettings
N_lay = len(layers)
for n,layer in enumerate(layers):
......
......@@ -93,8 +93,8 @@ class scurve(pyx.normpath.normcurve_pt):
class spath:
#A swomppy path is a list of modified PyX normsubpath items that can be used in a normpath for PyX operations
def __init__(self,inpoints,closed=False):
def __init__(self,inpoints,closed=False,attrs=None):
self.attrs=attrs
points = deepcopy(inpoints)
assert len(points)>1, "Must have at least two points"
if type(points) is list:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment