5 http://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands
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.
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
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'
25 def getCubicPath(elementNode):
27 end = evaluate.getVector3FromElementNode(elementNode)
28 previousElementNode = elementNode.getPreviousElementNode()
29 if previousElementNode == None:
30 print('Warning, can not get previousElementNode in getCubicPath in cubic for:')
33 begin = elementNode.getPreviousVertex(Vector3())
34 evaluatedControlPoints = evaluate.getTransformedPathByKey([], elementNode, 'controlPoints')
35 if len(evaluatedControlPoints) > 1:
36 return getCubicPathByBeginEnd(begin, evaluatedControlPoints, elementNode, end)
37 controlPoint0 = evaluate.getVector3ByPrefix(None, elementNode, 'controlPoint0')
38 controlPoint1 = evaluate.getVector3ByPrefix(None, elementNode, 'controlPoint1')
39 if len(evaluatedControlPoints) == 1:
40 controlPoint1 = evaluatedControlPoints[0]
41 if controlPoint0 == None:
42 oldControlPoint = evaluate.getVector3ByPrefixes(previousElementNode, ['controlPoint','controlPoint1'], None)
43 if oldControlPoint == None:
44 oldControlPoints = evaluate.getTransformedPathByKey([], previousElementNode, 'controlPoints')
45 if len(oldControlPoints) > 0:
46 oldControlPoint = oldControlPoints[-1]
47 if oldControlPoint == None:
49 controlPoint0 = begin + begin - oldControlPoint
50 return getCubicPathByBeginEnd(begin, [controlPoint0, controlPoint1], elementNode, end)
52 def getCubicPathByBeginEnd(begin, controlPoints, elementNode, end):
53 "Get the cubic path by begin and end."
54 return svg_reader.getCubicPoints(begin, controlPoints, end, lineation.getNumberOfBezierPoints(begin, elementNode, end))
56 def processElementNode(elementNode):
57 "Process the xml element."
58 elementNode.parentNode.xmlObject.vertexes += getCubicPath(elementNode)