chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / fabmetheus_utilities / geometry / manipulation_shapes / _outset.py
1 """
2 Create inset.
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 lineation
11 from fabmetheus_utilities.geometry.creation import solid
12 from fabmetheus_utilities.geometry.geometry_utilities.evaluate_elements import setting
13 from fabmetheus_utilities.geometry.geometry_utilities import boolean_solid
14 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
15 from fabmetheus_utilities.geometry.geometry_utilities import matrix
16 from fabmetheus_utilities.geometry.solids import triangle_mesh
17 from fabmetheus_utilities.vector3index import Vector3Index
18 from fabmetheus_utilities import euclidean
19 from fabmetheus_utilities import intercircle
20 import math
21
22
23 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
24 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
25 __date__ = '$Date: 2008/02/05 $'
26 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
27
28
29 globalExecutionOrder = 80
30
31
32 def getManipulatedGeometryOutput(elementNode, geometryOutput, prefix):
33         'Get outset geometryOutput.'
34         derivation = OutsetDerivation(elementNode, prefix)
35         if derivation.radius == 0.0:
36                 return geometryOutput
37         halfLayerHeight = 0.5 * derivation.radius
38         importRadius = 0.5 * derivation.radius * setting.getImportCoarseness(elementNode)
39         loopLayers = solid.getLoopLayersSetCopy(elementNode, geometryOutput, importRadius, derivation.radius)
40         if len(loopLayers) == 0:
41                 return triangle_mesh.getMeldedPillarOutput([])
42         triangleAltitude = math.sqrt(0.75) * derivation.radius
43         loops = []
44         vertexes = []
45         for loopLayerIndex in xrange(1, len(loopLayers), 2):
46                 loopLayer = loopLayers[loopLayerIndex]
47                 loopLayer.loops[0] = intercircle.getLargestInsetLoopFromLoop(loopLayer.loops[0], triangleAltitude)
48         z = loopLayers[0].z - derivation.radius
49         for loopIndex in xrange(-2, len(loopLayers) + 2, 2):
50                 loopLists = [[solid.getLoopOrEmpty(loopIndex - 2, loopLayers)]]
51                 loopLists.append([solid.getLoopOrEmpty(loopIndex - 1, loopLayers)])
52                 loopLists.append([intercircle.getLargestInsetLoopFromLoop(solid.getLoopOrEmpty(loopIndex, loopLayers), -derivation.radius)])
53                 loopLists.append([solid.getLoopOrEmpty(loopIndex + 1, loopLayers)])
54                 loopLists.append([solid.getLoopOrEmpty(loopIndex + 2, loopLayers)])
55                 largestLoop = euclidean.getLargestLoop(boolean_solid.getLoopsUnion(importRadius, loopLists))
56                 triangle_mesh.addVector3Loop(largestLoop, loops, vertexes, z)
57                 z += derivation.radius
58         return triangle_mesh.getMeldedPillarOutput(loops)
59
60 def getManipulatedPaths(close, elementNode, loop, prefix, sideLength):
61         "Get outset path."
62         derivation = OutsetDerivation(elementNode, prefix)
63         return intercircle.getInsetLoopsFromVector3Loop(loop, -derivation.radius)
64
65 def getNewDerivation(elementNode, prefix, sideLength):
66         'Get new derivation.'
67         return OutsetDerivation(elementNode, prefix)
68
69 def processElementNode(elementNode):
70         'Process the xml element.'
71         solid.processElementNodeByFunctionPair(elementNode, getManipulatedGeometryOutput, getManipulatedPaths)
72
73
74 class OutsetDerivation:
75         "Class to hold outset variables."
76         def __init__(self, elementNode, prefix):
77                 'Set defaults.'
78                 self.radius = evaluate.getEvaluatedFloat(2.0 * setting.getEdgeWidth(elementNode), elementNode, prefix + 'radius')