chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / geometry_utilities / evaluate_elements / setting.py
1 """
2 Boolean geometry utilities.
3
4 """
5
6 from __future__ import absolute_import
7
8 from skeinforge_application.skeinforge_utilities import skeinforge_craft
9 import math
10
11
12 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
13 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
14 __date__ = '$Date: 2008/02/05 $'
15 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
16
17
18 def _getAccessibleAttribute(attributeName, elementNode):
19         'Get the accessible attribute.'
20         if attributeName in globalGetAccessibleAttributeSet:
21                 return getattr(Setting(elementNode), attributeName, None)
22         return None
23
24 def getCascadeFloatWithoutSelf(defaultFloat, elementNode, key):
25         'Get the cascade float.'
26         if key in elementNode.attributes:
27                 value = elementNode.attributes[key]
28                 functionName = 'get' + key[0].upper() + key[1 :]
29                 if functionName in value:
30                         if elementNode.parentNode == None:
31                                 return defaultFloat
32                         else:
33                                 elementNode = elementNode.parentNode
34         return elementNode.getCascadeFloat(defaultFloat, key)
35
36 def getEdgeWidth(elementNode):
37         'Get the edge width.'
38         if elementNode == None:
39                 return 0.72
40         preferences = skeinforge_craft.getCraftPreferences('carve')
41         layerHeight = skeinforge_craft.getCraftValue('Layer Height', preferences)
42         layerHeight = getCascadeFloatWithoutSelf(layerHeight, elementNode, 'layerHeight')
43         edgeWidthOverHeight = skeinforge_craft.getCraftValue('Edge Width over Height', preferences)
44         edgeWidthOverHeight = getCascadeFloatWithoutSelf(edgeWidthOverHeight, elementNode, 'edgeWidthOverHeight')
45         return getCascadeFloatWithoutSelf(edgeWidthOverHeight * layerHeight, elementNode, 'edgeWidth')
46
47 def getImportCoarseness(elementNode, preferences=None):
48         'Get the importCoarseness.'
49         if elementNode == None:
50                 return 1.0
51         if preferences == None:
52                 preferences = skeinforge_craft.getCraftPreferences('carve')
53         importCoarseness = skeinforge_craft.getCraftValue('Import Coarseness', preferences)
54         return getCascadeFloatWithoutSelf(importCoarseness, elementNode, 'importCoarseness')
55
56 def getImportRadius(elementNode):
57         'Get the importRadius.'
58         if elementNode == None:
59                 return 0.36
60         preferences = skeinforge_craft.getCraftPreferences('carve')
61         importCoarseness = getImportCoarseness(elementNode, preferences)
62         layerHeight = skeinforge_craft.getCraftValue('Layer Height', preferences)
63         layerHeight = getCascadeFloatWithoutSelf(layerHeight, elementNode, 'layerHeight')
64         edgeWidthOverHeight = skeinforge_craft.getCraftValue('Edge Width over Height', preferences)
65         edgeWidthOverHeight = getCascadeFloatWithoutSelf(edgeWidthOverHeight, elementNode, 'edgeWidthOverHeight')
66         return getCascadeFloatWithoutSelf(0.5 * importCoarseness * layerHeight * edgeWidthOverHeight, elementNode, 'importRadius')
67
68 def getInteriorOverhangAngle(elementNode):
69         'Get the interior overhang support angle in degrees.'
70         return getCascadeFloatWithoutSelf(30.0, elementNode, 'interiorOverhangAngle')
71
72 def getInteriorOverhangRadians(elementNode):
73         'Get the interior overhang support angle in radians.'
74         return math.radians(getInteriorOverhangAngle(elementNode))
75
76 def getLayerHeight(elementNode):
77         'Get the layer height.'
78         if elementNode == None:
79                 return 0.4
80         preferences = skeinforge_craft.getCraftPreferences('carve')
81         return getCascadeFloatWithoutSelf(skeinforge_craft.getCraftValue('Layer Height', preferences), elementNode, 'layerHeight')
82
83 def getOverhangAngle(elementNode):
84         'Get the overhang support angle in degrees.'
85         return getCascadeFloatWithoutSelf(45.0, elementNode, 'overhangAngle')
86
87 def getOverhangRadians(elementNode):
88         'Get the overhang support angle in radians.'
89         return math.radians(getOverhangAngle(elementNode))
90
91 def getOverhangSpan(elementNode):
92         'Get the overhang span.'
93         return getCascadeFloatWithoutSelf(2.0 * getLayerHeight(elementNode), elementNode, 'overhangSpan')
94
95 def getPrecision(elementNode):
96         'Get the cascade precision.'
97         return getCascadeFloatWithoutSelf(0.2 * getLayerHeight(elementNode), elementNode, 'precision')
98
99 def getSheetThickness(elementNode):
100         'Get the sheet thickness.'
101         return getCascadeFloatWithoutSelf(3.0, elementNode, 'sheetThickness')
102
103 def getTwistPrecision(elementNode):
104         'Get the twist precision in degrees.'
105         return getCascadeFloatWithoutSelf(5.0, elementNode, 'twistPrecision')
106
107 def getTwistPrecisionRadians(elementNode):
108         'Get the twist precision in radians.'
109         return math.radians(getTwistPrecision(elementNode))
110
111
112 class Setting(object):
113         'Class to get handle elementNodes in a setting.'
114         def __init__(self, elementNode):
115                 'Initialize.'
116                 self.elementNode = elementNode
117
118         def __repr__(self):
119                 'Get the string representation of this Setting.'
120                 return self.elementNode
121
122         def getEdgeWidth(self):
123                 'Get the edge width.'
124                 return getEdgeWidth(self.elementNode)
125
126         def getImportCoarseness(self):
127                 'Get the importCoarseness.'
128                 return getImportCoarseness(self.elementNode)
129
130         def getImportRadius(self):
131                 'Get the importRadius.'
132                 return getImportRadius(self.elementNode)
133
134         def getInteriorOverhangAngle(self):
135                 'Get the interior overhang support angle in degrees.'
136                 return getInteriorOverhangAngle(self.elementNode)
137
138         def getInteriorOverhangRadians(self):
139                 'Get the interior overhang support angle in radians.'
140                 return getInteriorOverhangRadians(self.elementNode)
141
142         def getLayerHeight(self):
143                 'Get the layer height.'
144                 return getLayerHeight(self.elementNode)
145
146         def getOverhangAngle(self):
147                 'Get the overhang support angle in degrees.'
148                 return getOverhangAngle(self.elementNode)
149
150         def getOverhangRadians(self):
151                 'Get the overhang support angle in radians.'
152                 return getOverhangRadians(self.elementNode)
153
154         def getOverhangSpan(self):
155                 'Get the overhang span.'
156                 return getOverhangSpan(self.elementNode)
157
158         def getPrecision(self):
159                 'Get the cascade precision.'
160                 return getPrecision(self.elementNode)
161
162         def getSheetThickness(self):
163                 'Get the sheet thickness.'
164                 return getSheetThickness(self.elementNode)
165
166         def getTwistPrecision(self):
167                 'Get the twist precision in degrees.'
168                 return getTwistPrecision(self.elementNode)
169
170         def getTwistPrecisionRadians(self):
171                 'Get the twist precision in radians.'
172                 return getTwistPrecisionRadians(self.elementNode)
173
174
175 globalAccessibleAttributeDictionary = 'getEdgeWidth getImportCoarseness getImportRadius getInteriorOverhangAngle getInteriorOverhangRadians'.split()
176 globalAccessibleAttributeDictionary += 'getLayerHeight getOverhangSpan getOverhangAngle getOverhangRadians'.split()
177 globalAccessibleAttributeDictionary += 'getPrecision getSheetThickness getTwistPrecision getTwistPrecisionRadians'.split()
178 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)