chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / creation / shaft.py
1 """
2 Shaft path.
3
4 """
5
6 from __future__ import absolute_import
7
8 from fabmetheus_utilities.geometry.creation import lineation
9 from fabmetheus_utilities.geometry.geometry_tools import path
10 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
11 from fabmetheus_utilities import euclidean
12 import math
13
14
15 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
16 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
17 __date__ = '$Date: 2008/02/05 $'
18 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
19
20
21 def getGeometryOutput(derivation, elementNode):
22         "Get vector3 vertexes from attribute dictionary."
23         if derivation == None:
24                 derivation = ShaftDerivation(elementNode)
25         shaftPath = getShaftPath(derivation.depthBottom, derivation.depthTop, derivation.radius, derivation.sides)
26         return lineation.getGeometryOutputByLoop(elementNode, lineation.SideLoop(shaftPath))
27
28 def getGeometryOutputByArguments(arguments, elementNode):
29         "Get vector3 vertexes from attribute dictionary by arguments."
30         evaluate.setAttributesByArguments(['radius', 'sides'], arguments, elementNode)
31         return getGeometryOutput(None, elementNode)
32
33 def getNewDerivation(elementNode):
34         'Get new derivation.'
35         return ShaftDerivation(elementNode)
36
37 def getShaftPath(depthBottom, depthTop, radius, sides):
38         'Get shaft with the option of a flat on the top and/or bottom.'
39         if radius <= 0.0:
40                 return []
41         sideAngle = 2.0 * math.pi / float(abs(sides))
42         startAngle = 0.5 * sideAngle
43         endAngle = math.pi - 0.1 * sideAngle
44         shaftProfile = []
45         while startAngle < endAngle:
46                 unitPolar = euclidean.getWiddershinsUnitPolar(startAngle)
47                 shaftProfile.append(unitPolar * radius)
48                 startAngle += sideAngle
49         if abs(sides) % 2 == 1:
50                 shaftProfile.append(complex(-radius, 0.0))
51         horizontalBegin = radius - depthTop
52         horizontalEnd = depthBottom - radius
53         shaftProfile = euclidean.getHorizontallyBoundedPath(horizontalBegin, horizontalEnd, shaftProfile)
54         for shaftPointIndex, shaftPoint in enumerate(shaftProfile):
55                 shaftProfile[shaftPointIndex] = complex(shaftPoint.imag, shaftPoint.real)
56         shaftPath = euclidean.getVector3Path(euclidean.getMirrorPath(shaftProfile))
57         if sides > 0:
58                 shaftPath.reverse()
59         return shaftPath
60
61 def processElementNode(elementNode):
62         "Process the xml element."
63         path.convertElementNode(elementNode, getGeometryOutput(None, elementNode))
64
65
66 class ShaftDerivation(object):
67         "Class to hold shaft variables."
68         def __init__(self, elementNode):
69                 'Set defaults.'
70                 self.depthBottomOverRadius = evaluate.getEvaluatedFloat(0.0, elementNode, 'depthBottomOverRadius')
71                 self.depthTopOverRadius = evaluate.getEvaluatedFloat(0.0, elementNode, 'depthOverRadius')
72                 self.depthTopOverRadius = evaluate.getEvaluatedFloat(
73                         self.depthTopOverRadius, elementNode, 'depthTopOverRadius')
74                 self.radius = evaluate.getEvaluatedFloat(1.0, elementNode, 'radius')
75                 self.sides = evaluate.getEvaluatedInt(4, elementNode, 'sides')
76                 self.depthBottom = self.radius * self.depthBottomOverRadius
77                 self.depthBottom = evaluate.getEvaluatedFloat(self.depthBottom, elementNode, 'depthBottom')
78                 self.depthTop = self.radius * self.depthTopOverRadius
79                 self.depthTop = evaluate.getEvaluatedFloat(self.depthTop, elementNode, 'depth')
80                 self.depthTop = evaluate.getEvaluatedFloat(self.depthTop, elementNode, 'depthTop')