1 from __future__ import division
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11 class validFloat(object):
12 def __init__(self, setting, minValue = None, maxValue = None):
13 self.setting = setting
14 self.setting._validators.append(self)
15 self.minValue = minValue
16 self.maxValue = maxValue
20 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
21 if self.minValue is not None and f < self.minValue:
22 return ERROR, 'This setting should not be below ' + str(round(self.minValue, 3))
23 if self.maxValue is not None and f > self.maxValue:
24 return ERROR, 'This setting should not be above ' + str(self.maxValue)
26 except (ValueError, SyntaxError, TypeError, NameError):
27 return ERROR, '"' + str(self.setting.getValue()) + '" is not a valid number or expression'
29 class validInt(object):
30 def __init__(self, setting, minValue = None, maxValue = None):
31 self.setting = setting
32 self.setting._validators.append(self)
33 self.minValue = minValue
34 self.maxValue = maxValue
38 f = int(eval(self.setting.getValue(), {}, {}))
39 if self.minValue is not None and f < self.minValue:
40 return ERROR, 'This setting should not be below ' + str(self.minValue)
41 if self.maxValue is not None and f > self.maxValue:
42 return ERROR, 'This setting should not be above ' + str(self.maxValue)
44 except (ValueError, SyntaxError, TypeError, NameError):
45 return ERROR, '"' + str(self.setting.getValue()) + '" is not a valid whole number or expression'
47 class warningAbove(object):
48 def __init__(self, setting, minValueForWarning, warningMessage):
49 self.setting = setting
50 self.setting._validators.append(self)
51 self.minValueForWarning = minValueForWarning
52 self.warningMessage = warningMessage
56 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
57 if isinstance(self.minValueForWarning, types.FunctionType):
58 if f >= self.minValueForWarning():
59 return WARNING, self.warningMessage % (self.minValueForWarning())
61 if f >= self.minValueForWarning:
62 return WARNING, self.warningMessage
64 except (ValueError, SyntaxError, TypeError):
65 #We already have an error by the int/float validator in this case.
68 class warningBelow(object):
69 def __init__(self, setting, minValueForWarning, warningMessage):
70 self.setting = setting
71 self.setting._validators.append(self)
72 self.minValueForWarning = minValueForWarning
73 self.warningMessage = warningMessage
77 f = float(eval(self.setting.getValue().replace(',','.'), {}, {}))
78 if isinstance(self.minValueForWarning, types.FunctionType):
79 if f <= self.minValueForWarning():
80 return WARNING, self.warningMessage % (self.minValueForWarning())
82 if f <= self.minValueForWarning:
83 return WARNING, self.warningMessage
85 except (ValueError, SyntaxError, TypeError):
86 #We already have an error by the int/float validator in this case.
89 class wallThicknessValidator(object):
90 def __init__(self, setting):
91 self.setting = setting
92 self.setting._validators.append(self)
95 from Cura.util import profile
97 wallThickness = profile.getProfileSettingFloat('wall_thickness')
98 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
99 if wallThickness < 0.01:
101 if wallThickness <= nozzleSize * 0.5:
102 return ERROR, 'Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable'
103 if wallThickness <= nozzleSize * 0.85:
104 return WARNING, 'Trying to print walls thinner then the 0.8 * nozzle size. Small chance that this will produce usable results'
105 if wallThickness < nozzleSize:
108 return ERROR, 'Incorrect nozzle size'
110 lineCount = int(wallThickness / nozzleSize)
111 lineWidth = wallThickness / lineCount
112 lineWidthAlt = wallThickness / (lineCount + 1)
113 if lineWidth >= nozzleSize * 1.5 and lineWidthAlt <= nozzleSize * 0.85:
114 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'
117 #We already have an error by the int/float validator in this case.
120 class printSpeedValidator(object):
121 def __init__(self, setting):
122 self.setting = setting
123 self.setting._validators.append(self)
126 from Cura.util import profile
128 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
129 layerHeight = profile.getProfileSettingFloat('layer_height')
130 printSpeed = profile.getProfileSettingFloat('print_speed')
132 printVolumePerMM = layerHeight * nozzleSize
133 printVolumePerSecond = printVolumePerMM * printSpeed
134 #Using 10mm3 per second with a 0.4mm nozzle (normal max according to Joergen Geerds)
135 maxPrintVolumePerSecond = 10 / (math.pi*(0.2*0.2)) * (math.pi*(nozzleSize/2*nozzleSize/2))
137 if printVolumePerSecond > maxPrintVolumePerSecond:
138 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)
142 #We already have an error by the int/float validator in this case.