chiark / gitweb /
Move SF into its own directory, to seperate SF and Cura. Rename newui to gui.
[cura.git] / Cura / 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 #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.
8 import __init__
9
10 from skeinforge_application.skeinforge_utilities import skeinforge_craft
11 import math
12
13
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'
18
19
20 def _getAccessibleAttribute(attributeName, elementNode):
21         'Get the accessible attribute.'
22         if attributeName in globalGetAccessibleAttributeSet:
23                 return getattr(Setting(elementNode), attributeName, None)
24         return None
25
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:
33                                 return defaultFloat
34                         else:
35                                 elementNode = elementNode.parentNode
36         return elementNode.getCascadeFloat(defaultFloat, key)
37
38 def getEdgeWidth(elementNode):
39         'Get the edge width.'
40         if elementNode == None:
41                 return 0.72
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')
48
49 def getImportCoarseness(elementNode, preferences=None):
50         'Get the importCoarseness.'
51         if elementNode == None:
52                 return 1.0
53         if preferences == None:
54                 preferences = skeinforge_craft.getCraftPreferences('carve')
55         importCoarseness = skeinforge_craft.getCraftValue('Import Coarseness', preferences)
56         return getCascadeFloatWithoutSelf(importCoarseness, elementNode, 'importCoarseness')
57
58 def getImportRadius(elementNode):
59         'Get the importRadius.'
60         if elementNode == None:
61                 return 0.36
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')
69
70 def getInteriorOverhangAngle(elementNode):
71         'Get the interior overhang support angle in degrees.'
72         return getCascadeFloatWithoutSelf(30.0, elementNode, 'interiorOverhangAngle')
73
74 def getInteriorOverhangRadians(elementNode):
75         'Get the interior overhang support angle in radians.'
76         return math.radians(getInteriorOverhangAngle(elementNode))
77
78 def getLayerHeight(elementNode):
79         'Get the layer height.'
80         if elementNode == None:
81                 return 0.4
82         preferences = skeinforge_craft.getCraftPreferences('carve')
83         return getCascadeFloatWithoutSelf(skeinforge_craft.getCraftValue('Layer Height', preferences), elementNode, 'layerHeight')
84
85 def getOverhangAngle(elementNode):
86         'Get the overhang support angle in degrees.'
87         return getCascadeFloatWithoutSelf(45.0, elementNode, 'overhangAngle')
88
89 def getOverhangRadians(elementNode):
90         'Get the overhang support angle in radians.'
91         return math.radians(getOverhangAngle(elementNode))
92
93 def getOverhangSpan(elementNode):
94         'Get the overhang span.'
95         return getCascadeFloatWithoutSelf(2.0 * getLayerHeight(elementNode), elementNode, 'overhangSpan')
96
97 def getPrecision(elementNode):
98         'Get the cascade precision.'
99         return getCascadeFloatWithoutSelf(0.2 * getLayerHeight(elementNode), elementNode, 'precision')
100
101 def getSheetThickness(elementNode):
102         'Get the sheet thickness.'
103         return getCascadeFloatWithoutSelf(3.0, elementNode, 'sheetThickness')
104
105 def getTwistPrecision(elementNode):
106         'Get the twist precision in degrees.'
107         return getCascadeFloatWithoutSelf(5.0, elementNode, 'twistPrecision')
108
109 def getTwistPrecisionRadians(elementNode):
110         'Get the twist precision in radians.'
111         return math.radians(getTwistPrecision(elementNode))
112
113
114 class Setting:
115         'Class to get handle elementNodes in a setting.'
116         def __init__(self, elementNode):
117                 'Initialize.'
118                 self.elementNode = elementNode
119
120         def __repr__(self):
121                 'Get the string representation of this Setting.'
122                 return self.elementNode
123
124         def getEdgeWidth(self):
125                 'Get the edge width.'
126                 return getEdgeWidth(self.elementNode)
127
128         def getImportCoarseness(self):
129                 'Get the importCoarseness.'
130                 return getImportCoarseness(self.elementNode)
131
132         def getImportRadius(self):
133                 'Get the importRadius.'
134                 return getImportRadius(self.elementNode)
135
136         def getInteriorOverhangAngle(self):
137                 'Get the interior overhang support angle in degrees.'
138                 return getInteriorOverhangAngle(self.elementNode)
139
140         def getInteriorOverhangRadians(self):
141                 'Get the interior overhang support angle in radians.'
142                 return getInteriorOverhangRadians(self.elementNode)
143
144         def getLayerHeight(self):
145                 'Get the layer height.'
146                 return getLayerHeight(self.elementNode)
147
148         def getOverhangAngle(self):
149                 'Get the overhang support angle in degrees.'
150                 return getOverhangAngle(self.elementNode)
151
152         def getOverhangRadians(self):
153                 'Get the overhang support angle in radians.'
154                 return getOverhangRadians(self.elementNode)
155
156         def getOverhangSpan(self):
157                 'Get the overhang span.'
158                 return getOverhangSpan(self.elementNode)
159
160         def getPrecision(self):
161                 'Get the cascade precision.'
162                 return getPrecision(self.elementNode)
163
164         def getSheetThickness(self):
165                 'Get the sheet thickness.'
166                 return getSheetThickness(self.elementNode)
167
168         def getTwistPrecision(self):
169                 'Get the twist precision in degrees.'
170                 return getTwistPrecision(self.elementNode)
171
172         def getTwistPrecisionRadians(self):
173                 'Get the twist precision in radians.'
174                 return getTwistPrecisionRadians(self.elementNode)
175
176
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)