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 / manipulation_matrix / _scale.py
1 """
2 Boolean geometry scale.
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 matrix
12 from fabmetheus_utilities.vector3 import Vector3
13 from fabmetheus_utilities import euclidean
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 = 340
23
24
25 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
26         "Get equated geometryOutput."
27         scalePoints( elementNode, matrix.getVertexes(geometryOutput), prefix )
28         return geometryOutput
29
30 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
31         "Get equated paths."
32         scalePoints( elementNode, loop, prefix )
33         return [loop]
34
35 def getNewDerivation(elementNode, prefix, sideLength):
36         'Get new derivation.'
37         return ScaleDerivation(elementNode)
38
39 def manipulateElementNode(elementNode, target):
40         "Manipulate the xml element."
41         derivation = ScaleDerivation(elementNode)
42         if derivation.scaleTetragrid == None:
43                 print('Warning, scaleTetragrid was None in scale so nothing will be done for:')
44                 print(elementNode)
45                 return
46         matrix.setAttributesToMultipliedTetragrid(target, derivation.scaleTetragrid)
47
48 def processElementNode(elementNode):
49         "Process the xml element."
50         solid.processElementNodeByFunction(elementNode, manipulateElementNode)
51
52 def scalePoints(elementNode, points, prefix):
53         "Scale the points."
54         scaleVector3Default = Vector3(1.0, 1.0, 1.0)
55         scaleVector3 = matrix.getCumulativeVector3Remove(scaleVector3Default.copy(), elementNode, prefix)
56         if scaleVector3 == scaleVector3Default:
57                 return
58         for point in points:
59                 point.x *= scaleVector3.x
60                 point.y *= scaleVector3.y
61                 point.z *= scaleVector3.z
62
63
64 class ScaleDerivation:
65         "Class to hold scale variables."
66         def __init__(self, elementNode):
67                 'Set defaults.'
68                 self.scaleTetragrid = matrix.getScaleTetragrid(elementNode, '')