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 / _svg.py
1 """
2 Svg reader.
3
4 """
5
6
7 from __future__ import absolute_import
8 #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.
9 import __init__
10
11 from fabmetheus_utilities.geometry.creation import lineation
12 from fabmetheus_utilities.geometry.geometry_tools import path
13 from fabmetheus_utilities import euclidean
14 from fabmetheus_utilities import svg_reader
15
16
17 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
18 __credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>'
19 __date__ = '$Date: 2008/21/04 $'
20 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
21
22
23 def getGeometryOutput(derivation, elementNode):
24         "Get vector3 vertexes from attribute dictionary."
25         if derivation == None:
26                 derivation = SVGDerivation(elementNode)
27         return getGeometryOutputBySVGReader(elementNode, derivation.svgReader)
28
29 def getGeometryOutputByArguments(arguments, elementNode):
30         "Get vector3 vertexes from attribute dictionary by arguments."
31         derivation = SVGDerivation()
32         derivation.svgReader.parseSVG('', arguments[0])
33         return getGeometryOutput(derivation, elementNode)
34
35 def getGeometryOutputBySVGReader(elementNode, svgReader):
36         "Get vector3 vertexes from svgReader."
37         geometryOutput = []
38         for loopLayer in svgReader.loopLayers:
39                 for loop in loopLayer.loops:
40                         vector3Path = euclidean.getVector3Path(loop, loopLayer.z)
41                         sideLoop = lineation.SideLoop(vector3Path)
42                         sideLoop.rotate(elementNode)
43                         geometryOutput += lineation.getGeometryOutputByManipulation(elementNode, sideLoop)
44         return geometryOutput
45
46 def getNewDerivation(elementNode):
47         'Get new derivation.'
48         return SVGDerivation(elementNode)
49
50 def processElementNode(elementNode):
51         "Process the xml element."
52         path.convertElementNode(elementNode, getGeometryOutput(None, elementNode))
53
54
55 class SVGDerivation:
56         "Class to hold svg variables."
57         def __init__(self, elementNode):
58                 'Set defaults.'
59                 self.svgReader = svg_reader.SVGReader()
60                 self.svgReader.parseSVGByElementNode(elementNode)