chiark / gitweb /
Possible fix for the fluxline selection problem. Added first part of the dual-extrusi...
[cura.git] / Cura / util / gcodeGenerator.py
1 from __future__ import absolute_import
2
3 import math
4
5 from Cura.util import profile
6
7 class gcodeGenerator(object):
8         def __init__(self):
9                 self._feedPrint = profile.getProfileSettingFloat('print_speed') * 60
10                 self._feedTravel = profile.getProfileSettingFloat('travel_speed') * 60
11                 self._feedRetract = profile.getProfileSettingFloat('retraction_speed') * 60
12                 filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
13                 filamentArea = math.pi * filamentRadius * filamentRadius
14                 self._ePerMM = (profile.getProfileSettingFloat('nozzle_size') * 0.1) / filamentArea
15                 self._eValue = 0.0
16                 self._x = 0
17                 self._y = 0
18                 self._z = 0
19
20                 self._list = ['G92 E0']
21
22         def setExtrusionRate(self, lineWidth, layerHeight):
23                 filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
24                 filamentArea = math.pi * filamentRadius * filamentRadius
25                 self._ePerMM = (lineWidth * layerHeight) / filamentArea
26
27         def home(self):
28                 self._x = 0
29                 self._y = 0
30                 self._z = 0
31                 self._list += ['G28']
32
33         def addMove(self, x=None, y=None, z=None):
34                 cmd = "G0 "
35                 if x is not None:
36                         cmd += "X%f " % (x)
37                         self._x = x
38                 if y is not None:
39                         cmd += "Y%f " % (y)
40                         self._y = y
41                 if z is not None:
42                         cmd += "Z%f " % (z)
43                         self._z = z
44                 cmd += "F%d" % (self._feedTravel)
45                 self._list += [cmd]
46
47         def addPrime(self, amount=5):
48                 self._eValue += amount
49                 self._list += ['G1 E%f F%f' % (self._eValue, self._feedRetract)]
50
51         def addRetract(self, amount=5):
52                 self._eValue -= amount
53                 self._list += ['G1 E%f F%f' % (self._eValue, self._feedRetract)]
54
55         def addExtrude(self, x=None, y=None, z=None):
56                 cmd = "G1 "
57                 oldX = self._x
58                 oldY = self._y
59                 if x is not None:
60                         cmd += "X%f " % (x)
61                         self._x = x
62                 if y is not None:
63                         cmd += "Y%f " % (y)
64                         self._y = y
65                 if z is not None:
66                         cmd += "Z%f " % (z)
67                         self._z = z
68                 self._eValue += math.sqrt((self._x - oldX) * (self._x - oldX) + (self._y - oldY) * (self._y - oldY)) * self._ePerMM
69                 cmd += "E%f F%d" % (self._eValue, self._feedPrint)
70                 self._list += [cmd]
71
72         def addCmd(self, cmd):
73                 self._list += [cmd]
74
75         def list(self):
76                 return self._list