1 from __future__ import absolute_import
2 from __future__ import division
3 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
12 class validFloat(object):
13 def __init__(self, setting, minValue = None, maxValue = None):
14 self.setting = setting
15 self.setting._validators.append(self)
16 self.minValue = minValue
17 self.maxValue = maxValue
21 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
22 if self.minValue is not None and f < self.minValue:
23 return ERROR, 'This setting should not be below ' + str(round(self.minValue, 3))
24 if self.maxValue is not None and f > self.maxValue:
25 return ERROR, 'This setting should not be above ' + str(self.maxValue)
27 except (ValueError, SyntaxError, TypeError, NameError):
28 return ERROR, '"' + str(self.setting.getValue()) + '" is not a valid number or expression'
30 class validInt(object):
31 def __init__(self, setting, minValue = None, maxValue = None):
32 self.setting = setting
33 self.setting._validators.append(self)
34 self.minValue = minValue
35 self.maxValue = maxValue
39 f = int(eval(self.setting.getValue(), {}, {}))
40 if self.minValue is not None and f < self.minValue:
41 return ERROR, 'This setting should not be below ' + str(self.minValue)
42 if self.maxValue is not None and f > self.maxValue:
43 return ERROR, 'This setting should not be above ' + str(self.maxValue)
45 except (ValueError, SyntaxError, TypeError, NameError):
46 return ERROR, '"' + str(self.setting.getValue()) + '" is not a valid whole number or expression'
48 class warningAbove(object):
49 def __init__(self, setting, minValueForWarning, warningMessage):
50 self.setting = setting
51 self.setting._validators.append(self)
52 self.minValueForWarning = minValueForWarning
53 self.warningMessage = warningMessage
57 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
58 if isinstance(self.minValueForWarning, types.FunctionType):
59 if f >= self.minValueForWarning():
60 return WARNING, self.warningMessage % (self.minValueForWarning())
62 if f >= self.minValueForWarning:
63 return WARNING, self.warningMessage
65 except (ValueError, SyntaxError, TypeError):
66 #We already have an error by the int/float validator in this case.
69 class warningBelow(object):
70 def __init__(self, setting, minValueForWarning, warningMessage):
71 self.setting = setting
72 self.setting._validators.append(self)
73 self.minValueForWarning = minValueForWarning
74 self.warningMessage = warningMessage
78 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
79 if isinstance(self.minValueForWarning, types.FunctionType):
80 if f <= self.minValueForWarning():
81 return WARNING, self.warningMessage % (self.minValueForWarning())
83 if f <= self.minValueForWarning:
84 return WARNING, self.warningMessage
86 except (ValueError, SyntaxError, TypeError):
87 #We already have an error by the int/float validator in this case.
90 class wallThicknessValidator(object):
91 def __init__(self, setting):
92 self.setting = setting
93 self.setting._validators.append(self)
96 from Cura.util import profile
98 wallThickness = profile.getProfileSettingFloat('wall_thickness')
99 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
100 if wallThickness < 0.01:
102 if wallThickness <= nozzleSize * 0.5:
103 return ERROR, 'Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable'
104 if wallThickness <= nozzleSize * 0.85:
105 return WARNING, 'Trying to print walls thinner then the 0.8 * nozzle size. Small chance that this will produce usable results'
106 if wallThickness < nozzleSize:
109 return ERROR, 'Incorrect nozzle size'
111 lineCount = int(wallThickness / nozzleSize)
112 lineWidth = wallThickness / lineCount
113 lineWidthAlt = wallThickness / (lineCount + 1)
114 if lineWidth >= nozzleSize * 1.5 and lineWidthAlt <= nozzleSize * 0.85:
115 return WARNING, 'Current selected wall thickness results in a line thickness of ' + str(lineWidthAlt) + 'mm which is not recommended with your nozzle of ' + str(nozzleSize) + 'mm'
118 #We already have an error by the int/float validator in this case.
121 class printSpeedValidator(object):
122 def __init__(self, setting):
123 self.setting = setting
124 self.setting._validators.append(self)
127 from Cura.util import profile
129 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
130 layerHeight = profile.getProfileSettingFloat('layer_height')
131 printSpeed = profile.getProfileSettingFloat('print_speed')
133 printVolumePerMM = layerHeight * nozzleSize
134 printVolumePerSecond = printVolumePerMM * printSpeed
135 #Using 10mm3 per second with a 0.4mm nozzle (normal max according to Joergen Geerds)
136 maxPrintVolumePerSecond = 10 / (math.pi*(0.2*0.2)) * (math.pi*(nozzleSize/2*nozzleSize/2))
138 if printVolumePerSecond > maxPrintVolumePerSecond:
139 return WARNING, 'You are trying to print more then %.1fmm^3 of filament per second. This might cause filament slipping. (You are printing at %0.1fmm^3 per second)' % (maxPrintVolumePerSecond, printVolumePerSecond)
143 #We already have an error by the int/float validator in this case.