chiark / gitweb /
d233d4c2d33c89b1767c460a7e8f647ec492366e
[cura.git] / Cura / fabmetheus_utilities / geometry / geometry_tools / path_elements / quadratic.py
1 """
2 Quadratic vertexes.
3
4 From:
5 http://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands
6
7 """
8
9 from __future__ import absolute_import
10 #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.
11 import __init__
12
13 from fabmetheus_utilities.geometry.creation import lineation
14 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
15 from fabmetheus_utilities.vector3 import Vector3
16 from fabmetheus_utilities import svg_reader
17
18
19 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
20 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
21 __date__ = '$Date: 2008/02/05 $'
22 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
23
24
25 def getQuadraticPath(elementNode):
26         "Get the quadratic path."
27         end = evaluate.getVector3FromElementNode(elementNode)
28         previousElementNode = elementNode.getPreviousElementNode()
29         if previousElementNode == None:
30                 print('Warning, can not get previousElementNode in getQuadraticPath in quadratic for:')
31                 print(elementNode)
32                 return [end]
33         begin = elementNode.getPreviousVertex(Vector3())
34         controlPoint = evaluate.getVector3ByPrefix(None, elementNode, 'controlPoint')
35         if controlPoint == None:
36                 oldControlPoint = evaluate.getVector3ByPrefixes(previousElementNode, ['controlPoint','controlPoint1'], None)
37                 if oldControlPoint == None:
38                         oldControlPoint = end
39                 controlPoint = begin + begin - oldControlPoint
40                 evaluate.addVector3ToElementNode(elementNode, 'controlPoint', controlPoint)
41         return svg_reader.getQuadraticPoints(begin, controlPoint, end, lineation.getNumberOfBezierPoints(begin, elementNode, end))
42
43 def processElementNode(elementNode):
44         "Process the xml element."
45         elementNode.parentNode.xmlObject.vertexes += getQuadraticPath(elementNode)