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 wallThicknessValidator(object):
70 def __init__(self, setting):
71 self.setting = setting
72 self.setting._validators.append(self)
75 from Cura.util import profile
77 wallThickness = profile.getProfileSettingFloat('wall_thickness')
78 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
79 if wallThickness <= nozzleSize * 0.5:
80 return ERROR, 'Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable'
81 if wallThickness <= nozzleSize * 0.85:
82 return WARNING, 'Trying to print walls thinner then the 0.8 * nozzle size. Small chance that this will produce usable results'
83 if wallThickness < nozzleSize:
86 return ERROR, 'Incorrect nozzle size'
88 lineCount = int(wallThickness / nozzleSize)
89 lineWidth = wallThickness / lineCount
90 lineWidthAlt = wallThickness / (lineCount + 1)
91 if lineWidth >= nozzleSize * 1.5 and lineWidthAlt <= nozzleSize * 0.85:
92 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'
95 #We already have an error by the int/float validator in this case.
98 class printSpeedValidator(object):
99 def __init__(self, setting):
100 self.setting = setting
101 self.setting._validators.append(self)
104 from Cura.util import profile
106 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
107 layerHeight = profile.getProfileSettingFloat('layer_height')
108 printSpeed = profile.getProfileSettingFloat('print_speed')
110 printVolumePerMM = layerHeight * nozzleSize
111 printVolumePerSecond = printVolumePerMM * printSpeed
112 #Using 10mm3 per second with a 0.4mm nozzle (normal max according to Joergen Geerds)
113 maxPrintVolumePerSecond = 10 / (math.pi*(0.2*0.2)) * (math.pi*(nozzleSize/2*nozzleSize/2))
115 if printVolumePerSecond > maxPrintVolumePerSecond:
116 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)
120 #We already have an error by the int/float validator in this case.