5 http://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands
9 from __future__ import absolute_import
11 from fabmetheus_utilities.geometry.creation import lineation
12 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
13 from fabmetheus_utilities.vector3 import Vector3
14 from fabmetheus_utilities import svg_reader
17 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
18 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
19 __date__ = '$Date: 2008/02/05 $'
20 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
23 def getCubicPath(elementNode):
25 end = evaluate.getVector3FromElementNode(elementNode)
26 previousElementNode = elementNode.getPreviousElementNode()
27 if previousElementNode == None:
28 print('Warning, can not get previousElementNode in getCubicPath in cubic for:')
31 begin = elementNode.getPreviousVertex(Vector3())
32 evaluatedControlPoints = evaluate.getTransformedPathByKey([], elementNode, 'controlPoints')
33 if len(evaluatedControlPoints) > 1:
34 return getCubicPathByBeginEnd(begin, evaluatedControlPoints, elementNode, end)
35 controlPoint0 = evaluate.getVector3ByPrefix(None, elementNode, 'controlPoint0')
36 controlPoint1 = evaluate.getVector3ByPrefix(None, elementNode, 'controlPoint1')
37 if len(evaluatedControlPoints) == 1:
38 controlPoint1 = evaluatedControlPoints[0]
39 if controlPoint0 == None:
40 oldControlPoint = evaluate.getVector3ByPrefixes(previousElementNode, ['controlPoint','controlPoint1'], None)
41 if oldControlPoint == None:
42 oldControlPoints = evaluate.getTransformedPathByKey([], previousElementNode, 'controlPoints')
43 if len(oldControlPoints) > 0:
44 oldControlPoint = oldControlPoints[-1]
45 if oldControlPoint == None:
47 controlPoint0 = begin + begin - oldControlPoint
48 return getCubicPathByBeginEnd(begin, [controlPoint0, controlPoint1], elementNode, end)
50 def getCubicPathByBeginEnd(begin, controlPoints, elementNode, end):
51 "Get the cubic path by begin and end."
52 return svg_reader.getCubicPoints(begin, controlPoints, end, lineation.getNumberOfBezierPoints(begin, elementNode, end))
54 def processElementNode(elementNode):
55 "Process the xml element."
56 elementNode.parentNode.xmlObject.vertexes += getCubicPath(elementNode)