2 Boolean geometry utilities.
6 from __future__ import absolute_import
8 from skeinforge_application.skeinforge_utilities import skeinforge_craft
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'
18 def _getAccessibleAttribute(attributeName, elementNode):
19 'Get the accessible attribute.'
20 if attributeName in globalGetAccessibleAttributeSet:
21 return getattr(Setting(elementNode), attributeName, None)
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:
33 elementNode = elementNode.parentNode
34 return elementNode.getCascadeFloat(defaultFloat, key)
36 def getEdgeWidth(elementNode):
38 if elementNode == None:
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')
47 def getImportCoarseness(elementNode, preferences=None):
48 'Get the importCoarseness.'
49 if elementNode == None:
51 if preferences == None:
52 preferences = skeinforge_craft.getCraftPreferences('carve')
53 importCoarseness = skeinforge_craft.getCraftValue('Import Coarseness', preferences)
54 return getCascadeFloatWithoutSelf(importCoarseness, elementNode, 'importCoarseness')
56 def getImportRadius(elementNode):
57 'Get the importRadius.'
58 if elementNode == None:
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')
68 def getInteriorOverhangAngle(elementNode):
69 'Get the interior overhang support angle in degrees.'
70 return getCascadeFloatWithoutSelf(30.0, elementNode, 'interiorOverhangAngle')
72 def getInteriorOverhangRadians(elementNode):
73 'Get the interior overhang support angle in radians.'
74 return math.radians(getInteriorOverhangAngle(elementNode))
76 def getLayerHeight(elementNode):
77 'Get the layer height.'
78 if elementNode == None:
80 preferences = skeinforge_craft.getCraftPreferences('carve')
81 return getCascadeFloatWithoutSelf(skeinforge_craft.getCraftValue('Layer Height', preferences), elementNode, 'layerHeight')
83 def getOverhangAngle(elementNode):
84 'Get the overhang support angle in degrees.'
85 return getCascadeFloatWithoutSelf(45.0, elementNode, 'overhangAngle')
87 def getOverhangRadians(elementNode):
88 'Get the overhang support angle in radians.'
89 return math.radians(getOverhangAngle(elementNode))
91 def getOverhangSpan(elementNode):
92 'Get the overhang span.'
93 return getCascadeFloatWithoutSelf(2.0 * getLayerHeight(elementNode), elementNode, 'overhangSpan')
95 def getPrecision(elementNode):
96 'Get the cascade precision.'
97 return getCascadeFloatWithoutSelf(0.2 * getLayerHeight(elementNode), elementNode, 'precision')
99 def getSheetThickness(elementNode):
100 'Get the sheet thickness.'
101 return getCascadeFloatWithoutSelf(3.0, elementNode, 'sheetThickness')
103 def getTwistPrecision(elementNode):
104 'Get the twist precision in degrees.'
105 return getCascadeFloatWithoutSelf(5.0, elementNode, 'twistPrecision')
107 def getTwistPrecisionRadians(elementNode):
108 'Get the twist precision in radians.'
109 return math.radians(getTwistPrecision(elementNode))
112 class Setting(object):
113 'Class to get handle elementNodes in a setting.'
114 def __init__(self, elementNode):
116 self.elementNode = elementNode
119 'Get the string representation of this Setting.'
120 return self.elementNode
122 def getEdgeWidth(self):
123 'Get the edge width.'
124 return getEdgeWidth(self.elementNode)
126 def getImportCoarseness(self):
127 'Get the importCoarseness.'
128 return getImportCoarseness(self.elementNode)
130 def getImportRadius(self):
131 'Get the importRadius.'
132 return getImportRadius(self.elementNode)
134 def getInteriorOverhangAngle(self):
135 'Get the interior overhang support angle in degrees.'
136 return getInteriorOverhangAngle(self.elementNode)
138 def getInteriorOverhangRadians(self):
139 'Get the interior overhang support angle in radians.'
140 return getInteriorOverhangRadians(self.elementNode)
142 def getLayerHeight(self):
143 'Get the layer height.'
144 return getLayerHeight(self.elementNode)
146 def getOverhangAngle(self):
147 'Get the overhang support angle in degrees.'
148 return getOverhangAngle(self.elementNode)
150 def getOverhangRadians(self):
151 'Get the overhang support angle in radians.'
152 return getOverhangRadians(self.elementNode)
154 def getOverhangSpan(self):
155 'Get the overhang span.'
156 return getOverhangSpan(self.elementNode)
158 def getPrecision(self):
159 'Get the cascade precision.'
160 return getPrecision(self.elementNode)
162 def getSheetThickness(self):
163 'Get the sheet thickness.'
164 return getSheetThickness(self.elementNode)
166 def getTwistPrecision(self):
167 'Get the twist precision in degrees.'
168 return getTwistPrecision(self.elementNode)
170 def getTwistPrecisionRadians(self):
171 'Get the twist precision in radians.'
172 return getTwistPrecisionRadians(self.elementNode)
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)