chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / cura_sf / fabmetheus_utilities / geometry / manipulation_shapes / flip.py
1 """
2 Add material to support overhang or remove material at the overhang angle.
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 fabmetheus_utilities.geometry.creation import solid
11 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
12 from fabmetheus_utilities.geometry.geometry_utilities import matrix
13 from fabmetheus_utilities.vector3 import Vector3
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 globalExecutionOrder = 200
23
24
25 # http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=269576
26 # http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node159.html
27 #       m.a00 = -2 * norm.x * norm.x + 1;
28 #       m.a10 = -2 * norm.y * norm.x;
29 #       m.a20 = -2 * norm.z * norm.x;
30 #       m.a30 = 0;
31
32 #       m.a01 = -2 * norm.x * norm.y;
33 #       m.a11 = -2 * norm.y * norm.y + 1;
34 #       m.a21 = -2 * norm.z * norm.y;
35 #       m.a31 = 0;
36
37 #       m.a02 = -2 * norm.x * norm.z;
38 #       m.a12 = -2 * norm.y * norm.z;
39 #       m.a22 = -2 * norm.z * norm.z + 1;
40 #       m.a32 = 0;
41
42 #       m.a03 = -2 * norm.x * d;
43 #       m.a13 = -2 * norm.y * d;
44 #       m.a23 = -2 * norm.z * d;
45 #       m.a33 = 1;
46
47 # normal = unit_vector(normal[:3])
48 # M = numpy.identity(4)
49 # M[:3, :3] -= 2.0 * numpy.outer(normal, normal)
50 # M[:3, 3] = (2.0 * numpy.dot(point[:3], normal)) * normal
51 # return M
52 def flipPoints(elementNode, points, prefix):
53         'Flip the points.'
54         derivation = FlipDerivation(elementNode, prefix)
55         for point in points:
56                 point.setToVector3(point - 2.0 * derivation.axis.dot(point - derivation.origin) * derivation.axis)
57
58 def getFlippedLoop(elementNode, loop, prefix):
59         'Get flipped loop.'
60         flipPoints(elementNode, loop, prefix)
61         if getShouldReverse(elementNode, prefix):
62                 loop.reverse()
63         return loop
64
65 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
66         'Get equated geometryOutput.'
67         flipPoints(elementNode, matrix.getVertexes(geometryOutput), prefix)
68         return geometryOutput
69
70 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
71         'Get flipped paths.'
72         return [getFlippedLoop(elementNode, loop, prefix)]
73
74 def getNewDerivation(elementNode, prefix, sideLength):
75         'Get new derivation.'
76         return FlipDerivation(elementNode, prefix)
77
78 def getShouldReverse(elementNode, prefix):
79         'Determine if the loop should be reversed.'
80         return evaluate.getEvaluatedBoolean(True, elementNode, prefix + 'reverse')
81
82 def processElementNode(elementNode):
83         'Process the xml element.'
84         solid.processElementNodeByFunctionPair(elementNode, getManipulatedGeometryOutput, getManipulatedPaths)
85
86
87 class FlipDerivation:
88         "Class to hold flip variables."
89         def __init__(self, elementNode, prefix):
90                 'Set defaults.'
91                 self.origin = evaluate.getVector3ByPrefix(Vector3(), elementNode, prefix + 'origin')
92                 self.axis = evaluate.getVector3ByPrefix(Vector3(1.0, 0.0, 0.0), elementNode, prefix + 'axis').getNormalized()