1 from StringIO import StringIO
2 from config import config
3 from entities import NestedRing, GcodeCommand
4 from utilities import memory_tracker
5 import gcodes
6 import sys
7 import time
8
10 - def __init__(self, z, index, runtimeParameters):
11 self.z = z
12 self.index = index
13 self.runtimeParameters = runtimeParameters
14 self.bridgeRotation = None
15 self.nestedRings = []
16 self.preLayerGcodeCommands = []
17 self.postLayerGcodeCommands = []
18 self.feedAndFlowRateMultiplier = 1.0
19
20 self.preSupportGcodeCommands = []
21 self.postSupportGcodeCommands = []
22 self.supportPaths = []
23
24 if runtimeParameters.profileMemory:
25 memory_tracker.track_object(self)
26
27 if self.runtimeParameters.dimensionActive:
28 if self.runtimeParameters.extrusionUnitsRelative:
29 self.preLayerGcodeCommands.append(GcodeCommand(gcodes.RELATIVE_EXTRUSION_DISTANCE))
30 else:
31 self.preLayerGcodeCommands.append(GcodeCommand(gcodes.ABSOLUTE_EXTRUSION_DISTANCE))
32
33 self.combSkein = None
34
36 '''Get the string representation.'''
37 output = StringIO()
38
39 output.write('%2slayer (%s) z:%s\n' % ('', self.index, self.z))
40
41 output.write('%2slayer feedAndFlowRateMultiplier:%s\n' % ('', self.feedAndFlowRateMultiplier))
42
43 if self.bridgeRotation != None:
44 output.write('bridgeRotation: %s \n' % self.bridgeRotation)
45
46 output.write('%4spreLayerGcodeCommand:\n' % (''))
47 for preLayerGcodeCommand in self.preLayerGcodeCommands:
48 output.write('%4s %s' % ('',GcodeCommand.printCommand(preLayerGcodeCommand, self.runtimeParameters.verboseGcode)))
49
50 output.write('%4spreSupportGcodeCommands:\n' % (''))
51 for preSupportGcodeCommand in self.preSupportGcodeCommands:
52 output.write('%4s %s' % ('',GcodeCommand.printCommand(preSupportGcodeCommand, self.runtimeParameters.verboseGcode)))
53
54 output.write('%4ssupportLayerPaths:\n' % '')
55 for supportPath in self.supportPaths:
56 output.write(supportPath)
57
58 output.write('%4spostSupportGcodeCommands:\n' % (''))
59 for postSupportGcodeCommand in self.postSupportGcodeCommands:
60 output.write('%4s %s' % ('',GcodeCommand.printCommand(postSupportGcodeCommand, self.runtimeParameters.verboseGcode)))
61
62 output.write('%4snestedRings:' % (''))
63 for nestedRing in self.nestedRings:
64 output.write(nestedRing)
65
66 output.write('\n%4spostLayerGcodeCommand:' % (''))
67 for postLayerGcodeCommand in self.postLayerGcodeCommands:
68 output.write('%4s %s' % ('',GcodeCommand.printCommand(postLayerGcodeCommand, self.runtimeParameters.verboseGcode)))
69
70 return output.getvalue()
71
73 '''Returns the amount of time needed to print the layer, and the distance to travel. Note, this currently ignores commands in the pre and post layer list.'''
74 duration = 0.0
75 distance = 0.0
76 for nestedRing in self.nestedRings:
77 (nestedRingDistance, nestedRingDuration) = nestedRing.getDistanceAndDuration()
78 distance += nestedRingDistance
79 duration += nestedRingDuration
80 return (distance, duration)
81
82
84 pathList = []
85
86 self.getSupportPaths(pathList)
87
88 threadFunctionDictionary = {
89 'infill':self.getInfillPaths, 'loops':self.getLoopPaths, 'perimeter':self.getPerimeterPaths}
90 for threadType in self.runtimeParameters.extrusionPrintOrder:
91 threadFunctionDictionary[threadType](pathList)
92
93 return pathList
94
96 for supportPath in self.supportPaths:
97 pathList.append(supportPath)
98
102
104 for nestedRing in self.nestedRings:
105 nestedRing.getLoopPaths(pathList)
106
108 for nestedRing in self.nestedRings:
109 nestedRing.getInfillPaths(pathList)
110
112 if len(self.nestedRings) > 0:
113 return self.nestedRings[0].getStartPoint()
114
116 self.nestedRings.append(nestedRing)
117
119 return self.bridgeRotation != None
120