chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / cura_sf / skeinforge_application / skeinforge_plugins / craft_plugins / temperature.py
1 """
2 This page is in the table of contents.
3 Temperature is a plugin to set the temperature for the entire extrusion.
4
5 The temperature manual page is at:
6 http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Temperature
7
8 ==Operation==
9 The default 'Activate Temperature' checkbox is on.  When it is on, the functions described below will work, when it is off, nothing will be done.
10
11 ==Settings==
12 ===Rate===
13 The default cooling rate and heating rate for the extruder were both been derived from bothacker's graph at:
14 http://bothacker.com/wp-content/uploads/2009/09/18h5m53s9.29.2009.png
15
16 ====Cooling Rate====
17 Default is three degrees Celcius per second.
18
19 Defines the cooling rate of the extruder.
20
21 ====Heating Rate====
22 Default is ten degrees Celcius per second.
23
24 Defines the heating rate of the extruder.
25
26 ===Temperature===
27 ====Base Temperature====
28 Default for ABS is two hundred degrees Celcius.
29
30 Defines the raft base temperature.
31
32 ====Interface Temperature====
33 Default for ABS is two hundred degrees Celcius.
34
35 Defines the raft interface temperature.
36
37 ====Object First Layer Infill Temperature====
38 Default for ABS is 195 degrees Celcius.
39
40 Defines the infill temperature of the first layer of the object.
41
42 ====Object First Layer Perimeter Temperature====
43 Default for ABS is two hundred and twenty degrees Celcius.
44
45 Defines the edge temperature of the first layer of the object.
46
47 ====Object Next Layers Temperature====
48 Default for ABS is two hundred and thirty degrees Celcius.
49
50 Defines the temperature of the next layers of the object.
51
52 ====Support Layers Temperature====
53 Default for ABS is two hundred degrees Celcius.
54
55 Defines the support layers temperature.
56
57 ====Supported Layers Temperature====
58 Default for ABS is two hundred and thirty degrees Celcius.
59
60 Defines the temperature of the supported layers of the object, those layers which are right above a support layer.
61
62 ==Examples==
63 The following examples add temperature information to the file Screw Holder Bottom.stl.  The examples are run in a terminal in the folder which contains Screw Holder Bottom.stl and temperature.py.
64
65 > python temperature.py
66 This brings up the temperature dialog.
67
68 > python temperature.py Screw Holder Bottom.stl
69 The temperature tool is parsing the file:
70 Screw Holder Bottom.stl
71 ..
72 The temperature tool has created the file:
73 .. Screw Holder Bottom_temperature.gcode
74
75 """
76
77 from __future__ import absolute_import
78 #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.
79 import __init__
80
81 from fabmetheus_utilities.fabmetheus_tools import fabmetheus_interpret
82 from fabmetheus_utilities import archive
83 from fabmetheus_utilities import euclidean
84 from fabmetheus_utilities import gcodec
85 from fabmetheus_utilities import intercircle
86 from fabmetheus_utilities import settings
87 from skeinforge_application.skeinforge_utilities import skeinforge_craft
88 from skeinforge_application.skeinforge_utilities import skeinforge_polyfile
89 from skeinforge_application.skeinforge_utilities import skeinforge_profile
90 import math
91 import sys
92
93
94 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
95 __date__ = '$Date: 2008/21/04 $'
96 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
97
98
99 def getCraftedText( fileName, text='', repository=None):
100         "Temperature the file or text."
101         return getCraftedTextFromText(archive.getTextIfEmpty(fileName, text), repository)
102
103 def getCraftedTextFromText(gcodeText, repository=None):
104         "Temperature a gcode linear move text."
105         if gcodec.isProcedureDoneOrFileIsEmpty( gcodeText, 'temperature'):
106                 return gcodeText
107         if repository == None:
108                 repository = settings.getReadRepository( TemperatureRepository() )
109         if not repository.activateTemperature.value:
110                 return gcodeText
111         return TemperatureSkein().getCraftedGcode(gcodeText, repository)
112
113 def getNewRepository():
114         'Get new repository.'
115         return TemperatureRepository()
116
117 def writeOutput(fileName, shouldAnalyze=True):
118         "Temperature a gcode linear move file."
119         skeinforge_craft.writeChainTextWithNounMessage(fileName, 'temperature', shouldAnalyze)
120
121
122 class TemperatureRepository:
123         "A class to handle the temperature settings."
124         def __init__(self):
125                 "Set the default settings, execute title & settings fileName."
126                 skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_plugins.craft_plugins.temperature.html', self )
127                 self.fileNameInput = settings.FileNameInput().getFromFileName( fabmetheus_interpret.getGNUTranslatorGcodeFileTypeTuples(), 'Open File for Temperature', self, '')
128                 self.openWikiManualHelpPage = settings.HelpPage().getOpenFromAbsolute('http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Temperature')
129                 self.activateTemperature = settings.BooleanSetting().getFromValue('Activate Temperature', self, False )
130                 settings.LabelSeparator().getFromRepository(self)
131                 settings.LabelDisplay().getFromName('- Rate -', self )
132                 self.coolingRate = settings.FloatSpin().getFromValue( 1.0, 'Cooling Rate (Celcius/second):', self, 20.0, 3.0 )
133                 self.heatingRate = settings.FloatSpin().getFromValue( 1.0, 'Heating Rate (Celcius/second):', self, 20.0, 10.0 )
134                 settings.LabelSeparator().getFromRepository(self)
135                 settings.LabelDisplay().getFromName('- Temperature -', self )
136                 self.baseTemperature = settings.FloatSpin().getFromValue( 140.0, 'Base Temperature (Celcius):', self, 260.0, 200.0 )
137                 self.interfaceTemperature = settings.FloatSpin().getFromValue( 140.0, 'Interface Temperature (Celcius):', self, 260.0, 200.0 )
138                 self.objectFirstLayerInfillTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object First Layer Infill Temperature (Celcius):', self, 260.0, 195.0 )
139                 self.objectFirstLayerPerimeterTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object First Layer Perimeter Temperature (Celcius):', self, 260.0, 220.0 )
140                 self.objectNextLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object Next Layers Temperature (Celcius):', self, 260.0, 230.0 )
141                 self.supportLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Support Layers Temperature (Celcius):', self, 260.0, 200.0 )
142                 self.supportedLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Supported Layers Temperature (Celcius):', self, 260.0, 230.0 )
143                 self.executeTitle = 'Temperature'
144
145         def execute(self):
146                 "Temperature button has been clicked."
147                 fileNames = skeinforge_polyfile.getFileOrDirectoryTypesUnmodifiedGcode(self.fileNameInput.value, fabmetheus_interpret.getImportPluginFileNames(), self.fileNameInput.wasCancelled)
148                 for fileName in fileNames:
149                         writeOutput(fileName)
150
151
152 class TemperatureSkein:
153         "A class to temperature a skein of extrusions."
154         def __init__(self):
155                 self.distanceFeedRate = gcodec.DistanceFeedRate()
156                 self.lineIndex = 0
157                 self.lines = None
158
159         def getCraftedGcode(self, gcodeText, repository):
160                 "Parse gcode text and store the temperature gcode."
161                 self.repository = repository
162                 self.lines = archive.getTextLines(gcodeText)
163                 if self.repository.coolingRate.value < 0.1:
164                         print('The cooling rate should be more than 0.1, any cooling rate less than 0.1 will be treated as 0.1.')
165                         self.repository.coolingRate.value = 0.1
166                 if self.repository.heatingRate.value < 0.1:
167                         print('The heating rate should be more than 0.1, any heating rate less than 0.1 will be treated as 0.1.')
168                         self.repository.heatingRate.value = 0.1
169                 self.parseInitialization()
170                 self.distanceFeedRate.addLines( self.lines[self.lineIndex :] )
171                 return self.distanceFeedRate.output.getvalue()
172
173         def parseInitialization(self):
174                 'Parse gcode initialization and store the parameters.'
175                 for self.lineIndex in xrange(len(self.lines)):
176                         line = self.lines[self.lineIndex]
177                         splitLine = gcodec.getSplitLineBeforeBracketSemicolon(line)
178                         firstWord = gcodec.getFirstWord(splitLine)
179                         self.distanceFeedRate.parseSplitLine(firstWord, splitLine)
180                         if firstWord == '(</extruderInitialization>)':
181                                 self.distanceFeedRate.addTagBracketedProcedure('temperature')
182                                 return
183                         elif firstWord == '(<edgeWidth>':
184                                 self.distanceFeedRate.addTagBracketedLine('coolingRate', self.repository.coolingRate.value )
185                                 self.distanceFeedRate.addTagBracketedLine('heatingRate', self.repository.heatingRate.value )
186                                 self.distanceFeedRate.addTagBracketedLine('baseTemperature', self.repository.baseTemperature.value )
187                                 self.distanceFeedRate.addTagBracketedLine('interfaceTemperature', self.repository.interfaceTemperature.value )
188                                 self.distanceFeedRate.addTagBracketedLine('objectFirstLayerInfillTemperature', self.repository.objectFirstLayerInfillTemperature.value )
189                                 self.distanceFeedRate.addTagBracketedLine('objectFirstLayerPerimeterTemperature', self.repository.objectFirstLayerPerimeterTemperature.value )
190                                 self.distanceFeedRate.addTagBracketedLine('objectNextLayersTemperature', self.repository.objectNextLayersTemperature.value )
191                                 self.distanceFeedRate.addTagBracketedLine('supportLayersTemperature', self.repository.supportLayersTemperature.value )
192                                 self.distanceFeedRate.addTagBracketedLine('supportedLayersTemperature', self.repository.supportedLayersTemperature.value )
193                         self.distanceFeedRate.addLine(line)
194
195
196 def main():
197         "Display the temperature dialog."
198         if len(sys.argv) > 1:
199                 writeOutput(' '.join(sys.argv[1 :]))
200         else:
201                 settings.startMainLoopFromConstructor(getNewRepository())
202
203 if __name__ == "__main__":
204         main()