2 Boolean geometry utilities.
6 from __future__ import absolute_import
7 #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.
10 from skeinforge_application.skeinforge_utilities import skeinforge_craft
14 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
15 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
16 __date__ = '$Date: 2008/02/05 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
20 def _getAccessibleAttribute(attributeName, elementNode):
21 'Get the accessible attribute.'
22 if attributeName in globalGetAccessibleAttributeSet:
23 return getattr(Setting(elementNode), attributeName, None)
26 def getCascadeFloatWithoutSelf(defaultFloat, elementNode, key):
27 'Get the cascade float.'
28 if key in elementNode.attributes:
29 value = elementNode.attributes[key]
30 functionName = 'get' + key[0].upper() + key[1 :]
31 if functionName in value:
32 if elementNode.parentNode == None:
35 elementNode = elementNode.parentNode
36 return elementNode.getCascadeFloat(defaultFloat, key)
38 def getEdgeWidth(elementNode):
40 if elementNode == None:
42 preferences = skeinforge_craft.getCraftPreferences('carve')
43 layerHeight = skeinforge_craft.getCraftValue('Layer Height', preferences)
44 layerHeight = getCascadeFloatWithoutSelf(layerHeight, elementNode, 'layerHeight')
45 edgeWidthOverHeight = skeinforge_craft.getCraftValue('Edge Width over Height', preferences)
46 edgeWidthOverHeight = getCascadeFloatWithoutSelf(edgeWidthOverHeight, elementNode, 'edgeWidthOverHeight')
47 return getCascadeFloatWithoutSelf(edgeWidthOverHeight * layerHeight, elementNode, 'edgeWidth')
49 def getImportCoarseness(elementNode, preferences=None):
50 'Get the importCoarseness.'
51 if elementNode == None:
53 if preferences == None:
54 preferences = skeinforge_craft.getCraftPreferences('carve')
55 importCoarseness = skeinforge_craft.getCraftValue('Import Coarseness', preferences)
56 return getCascadeFloatWithoutSelf(importCoarseness, elementNode, 'importCoarseness')
58 def getImportRadius(elementNode):
59 'Get the importRadius.'
60 if elementNode == None:
62 preferences = skeinforge_craft.getCraftPreferences('carve')
63 importCoarseness = getImportCoarseness(elementNode, preferences)
64 layerHeight = skeinforge_craft.getCraftValue('Layer Height', preferences)
65 layerHeight = getCascadeFloatWithoutSelf(layerHeight, elementNode, 'layerHeight')
66 edgeWidthOverHeight = skeinforge_craft.getCraftValue('Edge Width over Height', preferences)
67 edgeWidthOverHeight = getCascadeFloatWithoutSelf(edgeWidthOverHeight, elementNode, 'edgeWidthOverHeight')
68 return getCascadeFloatWithoutSelf(0.5 * importCoarseness * layerHeight * edgeWidthOverHeight, elementNode, 'importRadius')
70 def getInteriorOverhangAngle(elementNode):
71 'Get the interior overhang support angle in degrees.'
72 return getCascadeFloatWithoutSelf(30.0, elementNode, 'interiorOverhangAngle')
74 def getInteriorOverhangRadians(elementNode):
75 'Get the interior overhang support angle in radians.'
76 return math.radians(getInteriorOverhangAngle(elementNode))
78 def getLayerHeight(elementNode):
79 'Get the layer height.'
80 if elementNode == None:
82 preferences = skeinforge_craft.getCraftPreferences('carve')
83 return getCascadeFloatWithoutSelf(skeinforge_craft.getCraftValue('Layer Height', preferences), elementNode, 'layerHeight')
85 def getOverhangAngle(elementNode):
86 'Get the overhang support angle in degrees.'
87 return getCascadeFloatWithoutSelf(45.0, elementNode, 'overhangAngle')
89 def getOverhangRadians(elementNode):
90 'Get the overhang support angle in radians.'
91 return math.radians(getOverhangAngle(elementNode))
93 def getOverhangSpan(elementNode):
94 'Get the overhang span.'
95 return getCascadeFloatWithoutSelf(2.0 * getLayerHeight(elementNode), elementNode, 'overhangSpan')
97 def getPrecision(elementNode):
98 'Get the cascade precision.'
99 return getCascadeFloatWithoutSelf(0.2 * getLayerHeight(elementNode), elementNode, 'precision')
101 def getSheetThickness(elementNode):
102 'Get the sheet thickness.'
103 return getCascadeFloatWithoutSelf(3.0, elementNode, 'sheetThickness')
105 def getTwistPrecision(elementNode):
106 'Get the twist precision in degrees.'
107 return getCascadeFloatWithoutSelf(5.0, elementNode, 'twistPrecision')
109 def getTwistPrecisionRadians(elementNode):
110 'Get the twist precision in radians.'
111 return math.radians(getTwistPrecision(elementNode))
115 'Class to get handle elementNodes in a setting.'
116 def __init__(self, elementNode):
118 self.elementNode = elementNode
121 'Get the string representation of this Setting.'
122 return self.elementNode
124 def getEdgeWidth(self):
125 'Get the edge width.'
126 return getEdgeWidth(self.elementNode)
128 def getImportCoarseness(self):
129 'Get the importCoarseness.'
130 return getImportCoarseness(self.elementNode)
132 def getImportRadius(self):
133 'Get the importRadius.'
134 return getImportRadius(self.elementNode)
136 def getInteriorOverhangAngle(self):
137 'Get the interior overhang support angle in degrees.'
138 return getInteriorOverhangAngle(self.elementNode)
140 def getInteriorOverhangRadians(self):
141 'Get the interior overhang support angle in radians.'
142 return getInteriorOverhangRadians(self.elementNode)
144 def getLayerHeight(self):
145 'Get the layer height.'
146 return getLayerHeight(self.elementNode)
148 def getOverhangAngle(self):
149 'Get the overhang support angle in degrees.'
150 return getOverhangAngle(self.elementNode)
152 def getOverhangRadians(self):
153 'Get the overhang support angle in radians.'
154 return getOverhangRadians(self.elementNode)
156 def getOverhangSpan(self):
157 'Get the overhang span.'
158 return getOverhangSpan(self.elementNode)
160 def getPrecision(self):
161 'Get the cascade precision.'
162 return getPrecision(self.elementNode)
164 def getSheetThickness(self):
165 'Get the sheet thickness.'
166 return getSheetThickness(self.elementNode)
168 def getTwistPrecision(self):
169 'Get the twist precision in degrees.'
170 return getTwistPrecision(self.elementNode)
172 def getTwistPrecisionRadians(self):
173 'Get the twist precision in radians.'
174 return getTwistPrecisionRadians(self.elementNode)
177 globalAccessibleAttributeDictionary = 'getEdgeWidth getImportCoarseness getImportRadius getInteriorOverhangAngle getInteriorOverhangRadians'.split()
178 globalAccessibleAttributeDictionary += 'getLayerHeight getOverhangSpan getOverhangAngle getOverhangRadians'.split()
179 globalAccessibleAttributeDictionary += 'getPrecision getSheetThickness getTwistPrecision getTwistPrecisionRadians'.split()
180 globalGetAccessibleAttributeSet = set(globalAccessibleAttributeDictionary)