chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / cura_sf / fabmetheus_utilities / geometry / creation / square.py
1 """
2 Square 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.vector3 import Vector3
12 from fabmetheus_utilities import euclidean
13 import math
14
15
16 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
17 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
18 __date__ = '$Date: 2008/02/05 $'
19 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
20
21
22 def getGeometryOutput(derivation, elementNode):
23         "Get vector3 vertexes from attribute dictionary."
24         if derivation == None:
25                 derivation = SquareDerivation(elementNode)
26         topRight = complex(derivation.topDemiwidth, derivation.demiheight)
27         topLeft = complex(-derivation.topDemiwidth, derivation.demiheight)
28         bottomLeft = complex(-derivation.bottomDemiwidth, -derivation.demiheight)
29         bottomRight = complex(derivation.bottomDemiwidth, -derivation.demiheight)
30         if derivation.interiorAngle != 90.0:
31                 interiorPlaneAngle = euclidean.getWiddershinsUnitPolar(math.radians(derivation.interiorAngle - 90.0))
32                 topRight = (topRight - bottomRight) * interiorPlaneAngle + bottomRight
33                 topLeft = (topLeft - bottomLeft) * interiorPlaneAngle + bottomLeft
34         lineation.setClosedAttribute(elementNode, derivation.revolutions)
35         complexLoop = [topRight, topLeft, bottomLeft, bottomRight]
36         originalLoop = complexLoop[:]
37         for revolution in xrange(1, derivation.revolutions):
38                 complexLoop += originalLoop
39         spiral = lineation.Spiral(derivation.spiral, 0.25)
40         loop = []
41         loopCentroid = euclidean.getLoopCentroid(originalLoop)
42         for point in complexLoop:
43                 unitPolar = euclidean.getNormalized(point - loopCentroid)
44                 loop.append(spiral.getSpiralPoint(unitPolar, Vector3(point.real, point.imag)))
45         return lineation.getGeometryOutputByLoop(elementNode, lineation.SideLoop(loop, 0.5 * math.pi))
46
47 def getGeometryOutputByArguments(arguments, elementNode):
48         "Get vector3 vertexes from attribute dictionary by arguments."
49         if len(arguments) < 1:
50                 return getGeometryOutput(None, elementNode)
51         inradius = 0.5 * euclidean.getFloatFromValue(arguments[0])
52         elementNode.attributes['inradius.x'] = str(inradius)
53         if len(arguments) > 1:
54                 inradius = 0.5 * euclidean.getFloatFromValue(arguments[1])
55         elementNode.attributes['inradius.y'] = str(inradius)
56         return getGeometryOutput(None, elementNode)
57
58 def getNewDerivation(elementNode):
59         'Get new derivation.'
60         return SquareDerivation(elementNode)
61
62 def processElementNode(elementNode):
63         "Process the xml element."
64         path.convertElementNode(elementNode, getGeometryOutput(None, elementNode))
65
66
67 class SquareDerivation(object):
68         "Class to hold square variables."
69         def __init__(self, elementNode):
70                 'Set defaults.'
71                 self.inradius = lineation.getInradius(complex(1.0, 1.0), elementNode)
72                 self.demiwidth = lineation.getFloatByPrefixBeginEnd(elementNode, 'demiwidth', 'width', self.inradius.real)
73                 self.demiheight = lineation.getFloatByPrefixBeginEnd(elementNode, 'demiheight', 'height', self.inradius.imag)
74                 self.bottomDemiwidth = lineation.getFloatByPrefixBeginEnd(elementNode, 'bottomdemiwidth', 'bottomwidth', self.demiwidth)
75                 self.topDemiwidth = lineation.getFloatByPrefixBeginEnd(elementNode, 'topdemiwidth', 'topwidth', self.demiwidth)
76                 self.interiorAngle = evaluate.getEvaluatedFloat(90.0, elementNode, 'interiorangle')
77                 self.revolutions = evaluate.getEvaluatedInt(1, elementNode, 'revolutions')
78                 self.spiral = evaluate.getVector3ByPrefix(None, elementNode, 'spiral')