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