1 from __future__ import absolute_import
2 from __future__ import division
8 from util import profile
14 class validFloat(object):
15 def __init__(self, setting, minValue = None, maxValue = None):
16 self.setting = setting
17 self.setting.validators.append(self)
18 self.minValue = minValue
19 self.maxValue = maxValue
23 f = float(eval(self.setting.GetValue().replace(',','.'), {}, {}))
24 if self.minValue != None and f < self.minValue:
25 return ERROR, 'This setting should not be below ' + str(self.minValue)
26 if self.maxValue != None and f > self.maxValue:
27 return ERROR, 'This setting should not be above ' + str(self.maxValue)
29 except (ValueError, SyntaxError, TypeError):
30 return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid number or expression'
32 class validInt(object):
33 def __init__(self, setting, minValue = None, maxValue = None):
34 self.setting = setting
35 self.setting.validators.append(self)
36 self.minValue = minValue
37 self.maxValue = maxValue
41 f = int(eval(self.setting.GetValue(), {}, {}))
42 if self.minValue != None and f < self.minValue:
43 return ERROR, 'This setting should not be below ' + str(self.minValue)
44 if self.maxValue != None and f > self.maxValue:
45 return ERROR, 'This setting should not be above ' + str(self.maxValue)
47 except (ValueError, SyntaxError, TypeError):
48 return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid whole number or expression'
50 class warningAbove(object):
51 def __init__(self, setting, minValueForWarning, warningMessage):
52 self.setting = setting
53 self.setting.validators.append(self)
54 self.minValueForWarning = minValueForWarning
55 self.warningMessage = warningMessage
59 f = float(eval(self.setting.GetValue().replace(',','.'), {}, {}))
60 if isinstance(self.minValueForWarning, types.FunctionType):
61 if f >= self.minValueForWarning():
62 return WARNING, self.warningMessage % (self.minValueForWarning())
64 if f >= self.minValueForWarning:
65 return WARNING, self.warningMessage
67 except (ValueError, SyntaxError, TypeError):
68 #We already have an error by the int/float validator in this case.
71 class wallThicknessValidator(object):
72 def __init__(self, setting):
73 self.setting = setting
74 self.setting.validators.append(self)
78 wallThickness = profile.getProfileSettingFloat('wall_thickness')
79 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
80 if wallThickness <= nozzleSize * 0.5:
81 return ERROR, 'Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable'
82 if wallThickness <= nozzleSize * 0.85:
83 return WARNING, 'Trying to print walls thinner then the 0.8 * nozzle size. Small chance that this will produce usable results'
84 if wallThickness < nozzleSize:
87 lineCount = int(wallThickness / nozzleSize)
88 lineWidth = wallThickness / lineCount
89 lineWidthAlt = wallThickness / (lineCount + 1)
90 if lineWidth >= nozzleSize * 1.5 and lineWidthAlt <= nozzleSize * 0.85:
91 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'
94 #We already have an error by the int/float validator in this case.
97 class printSpeedValidator(object):
98 def __init__(self, setting):
99 self.setting = setting
100 self.setting.validators.append(self)
104 nozzleSize = profile.getProfileSettingFloat('nozzle_size')
105 layerHeight = profile.getProfileSettingFloat('layer_height')
106 printSpeed = profile.getProfileSettingFloat('print_speed')
108 printVolumePerMM = layerHeight * nozzleSize
109 printVolumePerSecond = printVolumePerMM * printSpeed
110 #Using 10mm3 per second with a 0.4mm nozzle (normal max according to Joergen Geerds)
111 maxPrintVolumePerSecond = 10 / (math.pi*(0.2*0.2)) * (math.pi*(nozzleSize/2*nozzleSize/2))
113 if printVolumePerSecond > maxPrintVolumePerSecond:
114 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)
118 #We already have an error by the int/float validator in this case.