-
Notifications
You must be signed in to change notification settings - Fork 368
/
skirt.py
406 lines (345 loc) · 17.3 KB
/
skirt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
"""
This page is in the table of contents.
Skirt is a plugin to give the extruder some extra time to begin extruding properly before beginning the object, and to put a baffle around the model in order to keep the extrusion warm.
The skirt manual page is at:
http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Skirt
It is loosely based on Lenbook's outline plugin:
http://www.thingiverse.com/thing:4918
it is also loosely based on the outline that Nophead sometimes uses:
http://hydraraptor.blogspot.com/2010/01/hot-metal-and-serendipity.html
and also loosely based on the baffles that Nophead made to keep corners warm:
http://hydraraptor.blogspot.com/2010/09/some-corners-like-it-hot.html
If you want only an outline, set 'Layers To' to one. This gives the extruder some extra time to begin extruding properly before beginning your object, and gives you an early verification of where your object will be extruded.
If you also want an insulating skirt around the entire object, set 'Layers To' to a huge number, like 912345678. This will additionally make an insulating baffle around the object; to prevent moving air from cooling the object, which increases warping, especially in corners.
changed by Theodleif on 7/1/2012, added "the brim", look at http://forums.reprap.org/read.php?1,136147,136147#msg-136147
==Operation==
The default 'Activate Skirt' checkbox is off. When it is on, the functions described below will work, when it is off, nothing will be done.
==Settings==
===Convex===
Default is on.
When selected, the skirt will be convex, going around the model with only convex angles. If convex is not selected, the skirt will hug the model, going into every nook and cranny.
===Gap over Perimeter Width===
Default is three.
Defines the ratio of the gap between the object and the skirt over the edge width. If the ratio is too low, the skirt will connect to the object, if the ratio is too high, the skirt willl not provide much insulation for the object.
===Layers To===
Default is a one.
Defines the number of layers of the skirt. If you want only an outline, set 'Layers To' to one. If you want an insulating skirt around the entire object, set 'Layers To' to a huge number, like 912345678.
===Brim Width===
Default is zero.
Defines the numbers of skirt lines per layer. Used to prevent curling of edges. If you want to use the brim, set Gap over Perimeter Width to 0.5.
==Examples==
The following examples skirt the file Screw Holder Bottom.stl. The examples are run in a terminal in the folder which contains Screw Holder Bottom.stl and skirt.py.
> python skirt.py
This brings up the skirt dialog.
> python skirt.py Screw Holder Bottom.stl
The skirt tool is parsing the file:
Screw Holder Bottom.stl
..
The skirt tool has created the file:
.. Screw Holder Bottom_skirt.gcode
"""
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.fabmetheus_tools import fabmetheus_interpret
from fabmetheus_utilities.geometry.solids import triangle_mesh
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 intercircle
from fabmetheus_utilities import settings
from skeinforge_application.skeinforge_utilities import skeinforge_craft
from skeinforge_application.skeinforge_utilities import skeinforge_polyfile
from skeinforge_application.skeinforge_utilities import skeinforge_profile
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 getCraftedText(fileName, text='', repository=None):
'Skirt the fill file or text.'
return getCraftedTextFromText(archive.getTextIfEmpty(fileName, text), repository)
def getCraftedTextFromText(gcodeText, repository=None):
'Skirt the fill text.'
if gcodec.isProcedureDoneOrFileIsEmpty(gcodeText, 'skirt'):
return gcodeText
if repository == None:
repository = settings.getReadRepository(SkirtRepository())
if not repository.activateSkirt.value:
return gcodeText
return SkirtSkein().getCraftedGcode(gcodeText, repository)
def getNewRepository():
'Get new repository.'
return SkirtRepository()
def getOuterLoops(loops):
'Get widdershins outer loops.'
outerLoops = []
for loop in loops:
if not euclidean.isPathInsideLoops(outerLoops, loop):
outerLoops.append(loop)
intercircle.directLoops(True, outerLoops)
return outerLoops
def writeOutput(fileName, shouldAnalyze=True):
'Skirt a gcode linear move file.'
skeinforge_craft.writeChainTextWithNounMessage(fileName, 'skirt', shouldAnalyze)
class LoopCrossDictionary:
'Loop with a horizontal and vertical dictionary.'
def __init__(self):
'Initialize LoopCrossDictionary.'
self.loop = []
def __repr__(self):
'Get the string representation of this LoopCrossDictionary.'
return str(self.loop)
class SkirtRepository:
'A class to handle the skirt settings.'
def __init__(self):
'Set the default settings, execute title & settings fileName.'
skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_plugins.craft_plugins.skirt.html', self)
self.fileNameInput = settings.FileNameInput().getFromFileName(
fabmetheus_interpret.getGNUTranslatorGcodeFileTypeTuples(), 'Open File for Skirt', self, '')
self.openWikiManualHelpPage = settings.HelpPage().getOpenFromAbsolute('http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Skirt')
self.activateSkirt = settings.BooleanSetting().getFromValue('Activate Skirt', self, False)
self.baseShells = settings.IntSpin().getSingleIncrementFromValue(1, 'Base Shells (integer)', self, 10, 1)
self.convex = settings.BooleanSetting().getFromValue('Convex:', self, True)
self.gapOverEdgeWidth = settings.FloatSpin().getFromValue(1.0, 'Gap over Perimeter Width (ratio):', self, 5.0, 3.0)
self.layersTo = settings.IntSpin().getSingleIncrementFromValue(0, 'Layers To (index):', self, 912345678, 1)
self.brimWidth = settings.IntSpin().getSingleIncrementFromValue(0, 'Brim Width:', self, 50, 0)
self.executeTitle = 'Skirt'
def execute(self):
'Skirt button has been clicked.'
fileNames = skeinforge_polyfile.getFileOrDirectoryTypesUnmodifiedGcode(
self.fileNameInput.value, fabmetheus_interpret.getImportPluginFileNames(), self.fileNameInput.wasCancelled)
for fileName in fileNames:
writeOutput(fileName)
class SkirtSkein:
'A class to skirt a skein of extrusions.'
def __init__(self):
'Initialize variables.'
self.distanceFeedRate = gcodec.DistanceFeedRate()
self.feedRateMinute = None
self.isExtruderActive = False
self.isSupportLayer = False
self.layerIndex = -1
self.brimLine = 0
self.lineIndex = 0
self.lines = None
self.oldFlowRate = None
self.oldLocation = None
self.oldTemperatureInput = None
self.skirtFlowRate = None
self.skirtTemperature = None
self.travelFeedRateMinute = None
self.unifiedLoop = LoopCrossDictionary()
def addFlowRate(self, flowRate):
'Add a line of temperature if different.'
if flowRate != None:
self.distanceFeedRate.addLine('M108 S' + euclidean.getFourSignificantFigures(flowRate))
def addBrim(self, z):
'Add brim at z to gcode output.'
self.setSkirtFeedFlowTemperature()
self.distanceFeedRate.addLine('(<skirt>)')
oldTemperature = self.oldTemperatureInput
self.addTemperatureLineIfDifferent(self.skirtTemperature)
self.addFlowRate(self.skirtFlowRate)
for outsetLoop in self.outsetBrimLoops:
closedLoop = outsetLoop + [outsetLoop[0]]
self.distanceFeedRate.addGcodeFromFeedRateThreadZ(self.feedRateMinute, closedLoop, self.travelFeedRateMinute, z)
self.addFlowRate(self.oldFlowRate)
self.addTemperatureLineIfDifferent(oldTemperature)
self.distanceFeedRate.addLine('(</skirt>)')
def addSkirt(self, z):
'Add skirt at z to gcode output.'
self.setSkirtFeedFlowTemperature()
self.distanceFeedRate.addLine('(<skirt>)')
oldTemperature = self.oldTemperatureInput
self.addTemperatureLineIfDifferent(self.skirtTemperature)
self.addFlowRate(self.skirtFlowRate)
outsetLoops = self.baseOutsetLoops
if self.layerIndex > 0:
outsetLoops = self.upperOutsetLoops
for outsetLoop in outsetLoops:
closedLoop = outsetLoop + [outsetLoop[0]]
self.distanceFeedRate.addGcodeFromFeedRateThreadZ(self.feedRateMinute, closedLoop, self.travelFeedRateMinute, z)
self.addFlowRate(self.oldFlowRate)
self.addTemperatureLineIfDifferent(oldTemperature)
self.distanceFeedRate.addLine('(</skirt>)')
def addTemperatureLineIfDifferent(self, temperature):
'Add a line of temperature if different.'
if temperature == None or temperature == self.oldTemperatureInput:
return
self.distanceFeedRate.addLine('M104 S' + euclidean.getRoundedToThreePlaces(temperature))
self.oldTemperatureInput = temperature
def createSegmentDictionaries(self, loopCrossDictionary):
'Create horizontal and vertical segment dictionaries.'
loopCrossDictionary.horizontalDictionary = self.getHorizontalXIntersectionsTable(loopCrossDictionary.loop)
flippedLoop = euclidean.getDiagonalFlippedLoop(loopCrossDictionary.loop)
loopCrossDictionary.verticalDictionary = self.getHorizontalXIntersectionsTable(flippedLoop)
def createSkirtLoops(self):
'Create the skirt loops.'
points = euclidean.getPointsByHorizontalDictionary(self.edgeWidth, self.unifiedLoop.horizontalDictionary)
points += euclidean.getPointsByVerticalDictionary(self.edgeWidth, self.unifiedLoop.verticalDictionary)
loops = triangle_mesh.getDescendingAreaOrientedLoops(points, points, 2.5 * self.edgeWidth)
outerLoops = getOuterLoops(loops)
self.baseOutsetLoops = []
self.upperOutsetLoops = []
for shellIndex in xrange(self.repository.baseShells.value, 0, -1):
outsetLoops = intercircle.getInsetSeparateLoopsFromLoops(outerLoops, -self.skirtOutset - shellIndex * self.edgeWidth)
outsetLoops = getOuterLoops(outsetLoops)
if self.repository.convex.value:
outsetLoops = [euclidean.getLoopConvex(euclidean.getConcatenatedList(outsetLoops))]
self.baseOutsetLoops += outsetLoops
self.upperOutsetLoops = outsetLoops
if self.repository.brimWidth.value > 0:
points = euclidean.getPointsByHorizontalDictionary(self.edgeWidth, self.unifiedLoop.horizontalDictionary)
points += euclidean.getPointsByVerticalDictionary(self.edgeWidth, self.unifiedLoop.verticalDictionary)
loops = triangle_mesh.getDescendingAreaOrientedLoops(points, points, 2.5 * self.edgeWidth)
outerLoops = getOuterLoops(loops)
outsetLoops = intercircle.getInsetSeparateLoopsFromLoops(outerLoops, -self.edgeWidth*0.5)
outsetLoops = getOuterLoops(outsetLoops)
# if self.repository.convex.value:
# outsetLoops = [euclidean.getLoopConvex(euclidean.getConcatenatedList(outsetLoops))]
self.outsetBrimLoops = outsetLoops
for self.brimLine in xrange(self.brimLine+1,self.repository.brimWidth.value):
points = euclidean.getPointsByHorizontalDictionary(self.edgeWidth, self.unifiedLoop.horizontalDictionary)
points += euclidean.getPointsByVerticalDictionary(self.edgeWidth, self.unifiedLoop.verticalDictionary)
loops = triangle_mesh.getDescendingAreaOrientedLoops(points, points, 2.5 * self.edgeWidth)
outerLoops = getOuterLoops(loops)
outsetLoops = intercircle.getInsetSeparateLoopsFromLoops(outerLoops, -self.edgeWidth*(self.brimLine+0.5))
outsetLoops = getOuterLoops(outsetLoops)
# if self.repository.convex.value:
# outsetLoops = [euclidean.getLoopConvex(euclidean.getConcatenatedList(outsetLoops))]
self.outsetBrimLoops += outsetLoops
def getCraftedGcode(self, gcodeText, repository):
'Parse gcode text and store the skirt gcode.'
self.repository = repository
self.lines = archive.getTextLines(gcodeText)
self.parseInitialization()
self.parseBoundaries()
self.createSkirtLoops()
for self.lineIndex in xrange(self.lineIndex, len(self.lines)):
line = self.lines[self.lineIndex]
self.parseLine(line)
return gcodec.getGcodeWithoutDuplication('M108', self.distanceFeedRate.output.getvalue())
def getHorizontalXIntersectionsTable(self, loop):
'Get the horizontal x intersections table from the loop.'
horizontalXIntersectionsTable = {}
euclidean.addXIntersectionsFromLoopForTable(loop, horizontalXIntersectionsTable, self.edgeWidth)
return horizontalXIntersectionsTable
def parseBoundaries(self):
'Parse the boundaries and union them.'
self.createSegmentDictionaries(self.unifiedLoop)
if self.repository.layersTo.value < 1:
return
loopCrossDictionary = None
layerIndex = -1
for line in self.lines[self.lineIndex :]:
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
firstWord = gcodec.getFirstWord(splitLine)
if firstWord == '(</boundaryPerimeter>)' or firstWord == '(</raftPerimeter>)':
self.createSegmentDictionaries(loopCrossDictionary)
self.unifyLayer(loopCrossDictionary)
loopCrossDictionary = None
elif firstWord == '(<boundaryPoint>' or firstWord == '(<raftPoint>':
location = gcodec.getLocationFromSplitLine(None, splitLine)
if loopCrossDictionary == None:
loopCrossDictionary = LoopCrossDictionary()
loopCrossDictionary.loop.append(location.dropAxis())
elif firstWord == '(<layer>':
layerIndex += 1
if layerIndex > self.repository.layersTo.value:
return
settings.printProgress(layerIndex, 'skirt')
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)
self.distanceFeedRate.parseSplitLine(firstWord, splitLine)
if firstWord == '(</extruderInitialization>)':
self.distanceFeedRate.addTagBracketedProcedure('skirt')
return
elif firstWord == '(<objectNextLayersTemperature>':
self.oldTemperatureInput = float(splitLine[1])
self.skirtTemperature = self.oldTemperatureInput
elif firstWord == '(<edgeFeedRatePerSecond>':#todo make it firstlayer
self.feedRateMinute = 60.0 * float(splitLine[1])
elif firstWord == '(<operatingFlowRate>':
self.oldFlowRate = float(splitLine[1])
self.skirtFlowRate = self.oldFlowRate
elif firstWord == '(<edgeWidth>':
self.edgeWidth = float(splitLine[1])
self.skirtOutset = (self.repository.gapOverEdgeWidth.value + 0.5) * self.edgeWidth
self.distanceFeedRate.addTagRoundedLine('skirtOutset', self.skirtOutset)
elif firstWord == '(<travelFeedRatePerSecond>':#todo make it firstlayer
self.travelFeedRateMinute = 60.0 * float(splitLine[1])
self.distanceFeedRate.addLine(line)
def parseLine(self, line):
'Parse a gcode line and add it to the skirt skein.'
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
if len(splitLine) < 1:
return
firstWord = splitLine[0]
if firstWord == '(<raftPerimeter>)' or firstWord == '(</raftPerimeter>)' or firstWord == '(<raftPoint>':
return
self.distanceFeedRate.addLine(line)
if firstWord == 'G1':
self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine)
elif firstWord == '(<layer>':
self.layerIndex += 1
if self.layerIndex < self.repository.layersTo.value:
self.addSkirt(float(splitLine[1]))
if (self.layerIndex < 1) and (self.repository.brimWidth.value > 0):
self.addBrim(float(splitLine[1]))
elif firstWord == 'M101':
self.isExtruderActive = True
elif firstWord == 'M103':
self.isExtruderActive = False
elif firstWord == 'M104':
self.oldTemperatureInput = gcodec.getDoubleAfterFirstLetter(splitLine[1])
self.skirtTemperature = self.oldTemperatureInput
elif firstWord == 'M108':
self.oldFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1])
self.skirtFlowRate = self.oldFlowRate
elif firstWord == '(<supportLayer>)':
self.isSupportLayer = True
elif firstWord == '(</supportLayer>)':
self.isSupportLayer = False
def setSkirtFeedFlowTemperature(self):
'Set the skirt feed rate, flow rate and temperature to that of the next extrusion.'
isExtruderActive = self.isExtruderActive
isSupportLayer = self.isSupportLayer
for lineIndex in xrange(self.lineIndex, len(self.lines)):
line = self.lines[lineIndex]
splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
firstWord = gcodec.getFirstWord(splitLine)
if firstWord == 'G1':
self.feedRateMinute = gcodec.getFeedRateMinute(self.feedRateMinute, splitLine)
if isExtruderActive:
if not isSupportLayer:
return
elif firstWord == 'M101':
isExtruderActive = True
elif firstWord == 'M103':
isExtruderActive = False
elif firstWord == 'M104':
self.skirtTemperature = gcodec.getDoubleAfterFirstLetter(splitLine[1])
elif firstWord == 'M108':
self.skirtFlowRate = gcodec.getDoubleAfterFirstLetter(splitLine[1])
elif firstWord == '(<supportLayer>)':
isSupportLayer = True
elif firstWord == '(</supportLayer>)':
isSupportLayer = False
def unifyLayer(self, loopCrossDictionary):
'Union the loopCrossDictionary with the unifiedLoop.'
euclidean.joinXIntersectionsTables(loopCrossDictionary.horizontalDictionary, self.unifiedLoop.horizontalDictionary)
euclidean.joinXIntersectionsTables(loopCrossDictionary.verticalDictionary, self.unifiedLoop.verticalDictionary)
def main():
'Display the skirt dialog.'
if len(sys.argv) > 1:
writeOutput(' '.join(sys.argv[1 :]))
else:
settings.startMainLoopFromConstructor(getNewRepository())
if __name__ == '__main__':
main()