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 / creation / _drill.py
1 """
2 Drill negative solid.
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 extrude
11 from fabmetheus_utilities.geometry.creation import lineation
12 from fabmetheus_utilities.geometry.creation import solid
13 from fabmetheus_utilities.geometry.creation import teardrop
14 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
15 from fabmetheus_utilities.geometry.solids import triangle_mesh
16 from fabmetheus_utilities.vector3 import Vector3
17 from fabmetheus_utilities import euclidean
18 import math
19
20
21 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
22 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
23 __date__ = '$Date: 2008/02/05 $'
24 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
25
26
27 def getGeometryOutput(derivation, elementNode):
28         "Get vector3 vertexes from attribute dictionary."
29         if derivation == None:
30                 derivation = DrillDerivation(elementNode)
31         negatives = []
32         teardrop.addNegativesByRadius(elementNode, derivation.end, negatives, derivation.radius, derivation.start)
33         return solid.getGeometryOutputByManipulation(elementNode, negatives[0])
34
35 def getGeometryOutputByArguments(arguments, elementNode):
36         "Get vector3 vertexes from attribute dictionary by arguments."
37         evaluate.setAttributesByArguments(['radius', 'start', 'end'], arguments, elementNode)
38         return getGeometryOutput(None, elementNode)
39
40 def getNewDerivation(elementNode):
41         'Get new derivation.'
42         return DrillDerivation(elementNode)
43
44 def processElementNode(elementNode):
45         "Process the xml element."
46         solid.processElementNodeByGeometry(elementNode, getGeometryOutput(None, elementNode))
47
48
49 class DrillDerivation:
50         "Class to hold drill variables."
51         def __init__(self, elementNode):
52                 'Set defaults.'
53                 self.elementNode = elementNode
54                 self.end = evaluate.getVector3ByPrefix(Vector3(0.0, 0.0, 1.0), elementNode, 'end')
55                 self.start = evaluate.getVector3ByPrefix(Vector3(), elementNode, 'start')
56                 self.radius = lineation.getFloatByPrefixBeginEnd(elementNode, 'radius', 'diameter', 1.0)
57                 size = evaluate.getEvaluatedFloat(None, elementNode, 'size')
58                 if size != None:
59                         self.radius = 0.5 * size