"""
from __future__ import absolute_import
+from __future__ import division
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
import __init__
def storedSetting(name):
return lambda setting: profile.getProfileSetting(name)
+def storedSettingFloat(name):
+ return lambda setting: profile.getProfileSettingFloat(name)
+def storedSettingInt(name):
+ return lambda setting: int(profile.getProfileSettingFloat(name))
def storedPreference(name):
return lambda setting: profile.getPreference(name)
def ifSettingAboveZero(name):
- return lambda setting: float(profile.getProfileSetting(name)) > 0
+ return lambda setting: profile.getProfileSettingFloat(name) > 0
def ifSettingIs(name, value):
return lambda setting: profile.getProfileSetting(name) == value
return '0'
def storedPercentSetting(name):
- return lambda setting: float(profile.getProfileSetting(name)) / 100
+ return lambda setting: profile.getProfileSettingFloat(name) / 100
def calculateEdgeWidth(setting):
return profile.calculateEdgeWidth()
def calculateShellsBase(setting):
edgeWidth = profile.calculateEdgeWidth()
- extraWall = float(profile.getProfileSetting('extra_base_wall_thickness'))
+ extraWall = profile.getProfileSettingFloat('extra_base_wall_thickness')
return profile.calculateLineCount() - 1 + int(extraWall / edgeWidth + 0.0001)
return profile.calculateSolidLayerCount()
def firstLayerSpeedRatio(setting):
- bottomSpeed = float(profile.getProfileSetting('bottom_layer_speed'))
- speed = float(profile.getProfileSetting('print_speed'))
+ bottomSpeed = profile.getProfileSettingFloat('bottom_layer_speed')
+ speed = profile.getProfileSettingFloat('print_speed')
return bottomSpeed/speed
def calcSupportDistanceRatio(setting):
edgeWidth = calculateEdgeWidth(setting)
- distance = float(profile.getProfileSetting('support_distance'))
+ distance = profile.getProfileSettingFloat('support_distance')
return distance / edgeWidth
def calculateMultiplyDistance(setting):
return 10.0 / edgeWidth
def calcBottomLayerFlowRateRatio(setting):
- bottomThickness = float(profile.getProfileSetting('bottom_thickness'))
- layerThickness = float(profile.getProfileSetting('layer_height'))
+ bottomThickness = profile.getProfileSettingFloat('bottom_thickness')
+ layerThickness = profile.getProfileSettingFloat('layer_height')
if bottomThickness < layerThickness:
return 1.0
return bottomThickness / layerThickness
def calcExtraBottomThickness(setting):
- bottomThickness = float(profile.getProfileSetting('bottom_thickness'))
- layerThickness = float(profile.getProfileSetting('layer_height'))
+ bottomThickness = profile.getProfileSettingFloat('bottom_thickness')
+ layerThickness = profile.getProfileSettingFloat('layer_height')
if bottomThickness < layerThickness:
return 0.0
return bottomThickness - layerThickness
def calcLayerSkip(setting):
- bottomThickness = float(profile.getProfileSetting('bottom_thickness'))
- layerThickness = float(profile.getProfileSetting('layer_height'))
+ bottomThickness = profile.getProfileSettingFloat('bottom_thickness')
+ layerThickness = profile.getProfileSettingFloat('layer_height')
if bottomThickness < layerThickness:
return 0
return int(math.ceil((bottomThickness - layerThickness) / layerThickness + 0.0001) - 1)
'Edge_Width_mm': calculateEdgeWidth,
'Extra_Decimal_Places_float': DEFSET,
'Import_Coarseness_ratio': DEFSET,
- 'Layer_Height_mm': storedSetting("layer_height"),
+ 'Layer_Height_mm': storedSettingFloat("layer_height"),
'Layers_From_index': calcLayerSkip,
'Layers_To_index': DEFSET,
'Correct_Mesh': DEFSET,
'FlipZ': storedSetting("flip_z"),
'SwapXZ': storedSetting("swap_xz"),
'SwapYZ': storedSetting("swap_yz"),
- 'Scale': storedSetting("model_scale"),
- 'Rotate': storedSetting("model_rotate_base"),
+ 'Scale': storedSettingFloat("model_scale"),
+ 'Rotate': storedSettingFloat("model_rotate_base"),
},'scale': {
'Activate_Scale': "False",
'XY_Plane_Scale_ratio': DEFSET,
},'inset': {
'Add_Custom_Code_for_Temperature_Reading': "False",
'Infill_in_Direction_of_Bridge': "True",
- 'Infill_Width': storedSetting("nozzle_size"),
+ 'Infill_Width': storedSettingFloat("nozzle_size"),
'Loop_Order_Choice': DEFSET,
'Overlap_Removal_Width_over_Perimeter_Width_ratio': DEFSET,
'Turn_Extruder_Heater_Off_at_Shut_Down': DEFSET,
'Line': ifSettingIs('infill_type', 'Line'),
'Infill_Perimeter_Overlap_ratio': storedPercentSetting('fill_overlap'),
'Infill_Solidity_ratio': storedPercentSetting('fill_density'),
- 'Infill_Width': storedSetting("nozzle_size"),
+ 'Infill_Width': storedSettingFloat("nozzle_size"),
'Sharpest_Angle_degrees': DEFSET,
'Solid_Surface_Thickness_layers': calculateSolidLayerCount,
'Start_From_Choice': DEFSET,
'Thread_Sequence_Choice': storedSetting('sequence'),
},'multiply': {
'Activate_Multiply': "True",
- 'Center_X_mm': storedSetting("machine_center_x"),
- 'Center_Y_mm': storedSetting("machine_center_y"),
+ 'Center_X_mm': storedSettingFloat("machine_center_x"),
+ 'Center_Y_mm': storedSettingFloat("machine_center_y"),
'Number_of_Columns_integer': storedSetting('model_multiply_x'),
'Number_of_Rows_integer': storedSetting('model_multiply_y'),
'Reverse_Sequence_every_Odd_Layer': DEFSET,
'Bridge_Flow_Rate_Multiplier_ratio': storedPercentSetting('bridge_material_amount'),
'Duty_Cyle_at_Beginning_portion': DEFSET,
'Duty_Cyle_at_Ending_portion': DEFSET,
- 'Feed_Rate_mm/s': storedSetting("print_speed"),
- 'Flow_Rate_Setting_float': storedSetting("print_speed"),
+ 'Feed_Rate_mm/s': storedSettingFloat("print_speed"),
+ 'Flow_Rate_Setting_float': storedSettingFloat("print_speed"),
'Object_First_Layer_Feed_Rate_Infill_Multiplier_ratio': firstLayerSpeedRatio,
'Object_First_Layer_Feed_Rate_Perimeter_Multiplier_ratio': firstLayerSpeedRatio,
'Object_First_Layer_Feed_Rate_Travel_Multiplier_ratio': firstLayerSpeedRatio,
'Maximum_Z_Feed_Rate_mm/s': DEFSET,
'Perimeter_Feed_Rate_Multiplier_ratio': DEFSET,
'Perimeter_Flow_Rate_Multiplier_ratio': DEFSET,
- 'Travel_Feed_Rate_mm/s': storedSetting("travel_speed"),
+ 'Travel_Feed_Rate_mm/s': storedSettingFloat("travel_speed"),
'Bottom_layer_flow_rate_ratio': calcBottomLayerFlowRateRatio,
},'temperature': {
'Activate_Temperature': DEFSET,#ifSettingAboveZero('print_temperature'),
'Cooling_Rate_Celcius/second': DEFSET,
'Heating_Rate_Celcius/second': DEFSET,
- 'Base_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Interface_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Object_First_Layer_Infill_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Object_First_Layer_Perimeter_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Object_Next_Layers_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Support_Layers_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
- 'Supported_Layers_Temperature_Celcius': DEFSET,#storedSetting("print_temperature"),
+ 'Base_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Interface_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Object_First_Layer_Infill_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Object_First_Layer_Perimeter_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Object_Next_Layers_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Support_Layers_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
+ 'Supported_Layers_Temperature_Celcius': DEFSET,#storedSettingFloat("print_temperature"),
},'raft': {
'Activate_Raft': "True",
'Add_Raft,_Elevate_Nozzle,_Orbit': DEFSET,
'Name_of_Support_Start_File': DEFSET,
'Operating_Nozzle_Lift_over_Layer_Thickness_ratio': DEFSET,
'Raft_Additional_Margin_over_Length_%': DEFSET,
- 'Raft_Margin_mm': storedSetting('raft_margin'),
+ 'Raft_Margin_mm': storedSettingFloat('raft_margin'),
'Support_Cross_Hatch': 'False',
'Support_Flow_Rate_over_Operating_Flow_Rate_ratio': storedPercentSetting('support_rate'),
'Support_Gap_over_Perimeter_Extrusion_Width_ratio': calcSupportDistanceRatio,
'Bridge_Cool_Celcius': DEFSET,
'Cool_Type': DEFSET,
'Maximum_Cool_Celcius': DEFSET,
- 'Minimum_Layer_Time_seconds': storedSetting("cool_min_layer_time"),
+ 'Minimum_Layer_Time_seconds': storedSettingFloat("cool_min_layer_time"),
'Minimum_Orbital_Radius_millimeters': DEFSET,
'Name_of_Cool_End_File': DEFSET,
'Name_of_Cool_Start_File': DEFSET,
'Orbital_Outset_millimeters': DEFSET,
'Turn_Fan_On_at_Beginning': storedSetting("fan_enabled"),
'Turn_Fan_Off_at_Ending': "False",
- 'Minimum_feed_rate_mm/s': storedSetting("cool_min_feedrate"),
- 'Fan_on_at_layer': storedSetting('fan_layer'),
- 'Fan_speed_%': storedSetting('fan_speed'),
+ 'Minimum_feed_rate_mm/s': storedSettingFloat("cool_min_feedrate"),
+ 'Fan_on_at_layer': storedSettingInt('fan_layer'),
+ 'Fan_speed_%': storedSettingInt('fan_speed'),
},'hop': {
'Activate_Hop': "False",
'Hop_Over_Layer_Thickness_ratio': DEFSET,
'Activate_Dimension': "True",
'Absolute_Extrusion_Distance': "True",
'Relative_Extrusion_Distance': "False",
- 'Extruder_Retraction_Speed_mm/s': storedSetting('retraction_speed'),
- 'Filament_Diameter_mm': storedSetting("filament_diameter"),
- 'Filament_Packing_Density_ratio': storedSetting("filament_density"),
+ 'Extruder_Retraction_Speed_mm/s': storedSettingFloat('retraction_speed'),
+ 'Filament_Diameter_mm': storedSettingFloat("filament_diameter"),
+ 'Filament_Packing_Density_ratio': storedSettingFloat("filament_density"),
'Maximum_E_Value_before_Reset_float': DEFSET,
- 'Minimum_Travel_for_Retraction_millimeters': storedSetting("retraction_min_travel"),
+ 'Minimum_Travel_for_Retraction_millimeters': storedSettingFloat("retraction_min_travel"),
'Retract_Within_Island': DEFSET,
- 'Retraction_Distance_millimeters': storedSetting('retraction_amount'),
- 'Restart_Extra_Distance_millimeters': storedSetting('retraction_extra'),
+ 'Retraction_Distance_millimeters': storedSettingFloat('retraction_amount'),
+ 'Restart_Extra_Distance_millimeters': storedSettingFloat('retraction_extra'),
},'alteration': {
'Activate_Alteration': "True",
'Name_of_End_File': "end.gcode",
from __future__ import absolute_import
+from __future__ import division
import __init__
import types
def validate(self):
try:
- f = float(self.setting.GetValue())
+ f = float(eval(self.setting.GetValue(), {}, {}))
if self.minValue != None and f < self.minValue:
return ERROR, 'This setting should not be below ' + str(self.minValue)
if self.maxValue != None and f > self.maxValue:
return ERROR, 'This setting should not be above ' + str(self.maxValue)
return SUCCESS, ''
- except ValueError:
- return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid number'
+ except (ValueError, SyntaxError):
+ return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid number or expression'
class validInt():
def __init__(self, setting, minValue = None, maxValue = None):
def validate(self):
try:
- f = int(self.setting.GetValue())
+ f = int(eval(self.setting.GetValue(), {}, {}))
if self.minValue != None and f < self.minValue:
return ERROR, 'This setting should not be below ' + str(self.minValue)
if self.maxValue != None and f > self.maxValue:
return ERROR, 'This setting should not be above ' + str(self.maxValue)
return SUCCESS, ''
- except ValueError:
- return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid whole number'
+ except (ValueError, SyntaxError):
+ return ERROR, '"' + str(self.setting.GetValue()) + '" is not a valid whole number or expression'
class warningAbove():
def __init__(self, setting, minValueForWarning, warningMessage):
def validate(self):
try:
- f = float(self.setting.GetValue())
+ f = float(eval(self.setting.GetValue(), {}, {}))
if isinstance(self.minValueForWarning, types.FunctionType):
if f >= self.minValueForWarning():
return WARNING, self.warningMessage % (self.minValueForWarning())
if f >= self.minValueForWarning:
return WARNING, self.warningMessage
return SUCCESS, ''
- except ValueError:
+ except (ValueError, SyntaxError):
#We already have an error by the int/float validator in this case.
return SUCCESS, ''
def validate(self):
try:
- wallThickness = float(self.setting.GetValue())
- nozzleSize = float(profile.getProfileSetting('nozzle_size'))
+ wallThickness = profile.getProfileSettingFloat('wall_thickness')
+ nozzleSize = profile.getProfileSettingFloat('nozzle_size')
if wallThickness <= nozzleSize * 0.5:
return ERROR, 'Trying to print walls thinner then the half of your nozzle size, this will not produce anything usable'
if wallThickness <= nozzleSize * 0.85:
def validate(self):
try:
- nozzleSize = float(profile.getProfileSetting('nozzle_size'))
- layerHeight = float(profile.getProfileSetting('layer_height'))
- printSpeed = float(profile.getProfileSetting('print_speed'))
+ nozzleSize = profile.getProfileSettingFloat('nozzle_size')
+ layerHeight = profile.getProfileSettingFloat('layer_height')
+ printSpeed = profile.getProfileSettingFloat('print_speed')
printVolumePerMM = layerHeight * nozzleSize
printVolumePerSecond = printVolumePerMM * printSpeed
from __future__ import absolute_import\r
+from __future__ import division\r
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.\r
import __init__\r
\r
if not globalProfileParser.has_section('profile'):\r
globalProfileParser.add_section('profile')\r
globalProfileParser.set('profile', name, str(default))\r
- print name + " not found in profile, so using default: " + str(default)\r
+ #print name + " not found in profile, so using default: " + str(default)\r
return default\r
return globalProfileParser.get('profile', name)\r
\r
+def getProfileSettingFloat(name):\r
+ try:\r
+ return float(eval(getProfileSetting(name), {}, {}))\r
+ except (ValueError, SyntaxError):\r
+ return 0.0\r
+\r
def putProfileSetting(name, value):\r
#Check if we have a configuration file loaded, else load the default.\r
if not globals().has_key('globalProfileParser'):\r
if not globalPreferenceParser.has_section('preference'):\r
globalPreferenceParser.add_section('preference')\r
globalPreferenceParser.set('preference', name, str(default))\r
- print name + " not found in preferences, so using default: " + str(default)\r
+ #print name + " not found in preferences, so using default: " + str(default)\r
return default\r
return unicode(globalPreferenceParser.get('preference', name), "utf-8")\r
\r
## Utility functions to calculate common profile values\r
#########################################################\r
def calculateEdgeWidth():\r
- wallThickness = float(getProfileSetting('wall_thickness'))\r
- nozzleSize = float(getProfileSetting('nozzle_size'))\r
+ wallThickness = getProfileSettingFloat('wall_thickness')\r
+ nozzleSize = getProfileSettingFloat('nozzle_size')\r
\r
if wallThickness < nozzleSize:\r
return wallThickness\r
return lineWidth\r
\r
def calculateLineCount():\r
- wallThickness = float(getProfileSetting('wall_thickness'))\r
- nozzleSize = float(getProfileSetting('nozzle_size'))\r
+ wallThickness = getProfileSettingFloat('wall_thickness')\r
+ nozzleSize = getProfileSettingFloat('nozzle_size')\r
\r
if wallThickness < nozzleSize:\r
return 1\r
return lineCount\r
\r
def calculateSolidLayerCount():\r
- layerHeight = float(getProfileSetting('layer_height'))\r
- solidThickness = float(getProfileSetting('solid_layer_thickness'))\r
+ layerHeight = getProfileSettingFloat('layer_height')\r
+ solidThickness = getProfileSettingFloat('solid_layer_thickness')\r
return int(math.ceil(solidThickness / layerHeight - 0.0001))\r
\r
#########################################################\r
eSteps = float(getPreference('steps_per_e'))\r
if eSteps > 0:\r
prefix += 'M92 E'+str(eSteps)+'\n'\r
- temp = float(getProfileSetting('print_temperature'))\r
+ temp = getProfileSettingFloat('print_temperature')\r
if temp > 0:\r
prefix += 'M109 S'+str(temp)+'\n'\r
elif filename == 'replace.csv':\r