SVG ellipse support.
This commit is contained in:
@@ -244,7 +244,7 @@ class FlatCAMGUI(QtGui.QMainWindow):
|
|||||||
self.setWindowIcon(self.app_icon)
|
self.setWindowIcon(self.app_icon)
|
||||||
|
|
||||||
self.setGeometry(100, 100, 1024, 650)
|
self.setGeometry(100, 100, 1024, 650)
|
||||||
self.setWindowTitle('FlatCAM %s' % version)
|
self.setWindowTitle('FlatCAM %s - Development Version' % version)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
|
|||||||
32
svgparse.py
32
svgparse.py
@@ -21,6 +21,7 @@ import itertools
|
|||||||
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
|
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
|
||||||
from shapely.geometry import LinearRing, LineString, Point
|
from shapely.geometry import LinearRing, LineString, Point
|
||||||
from shapely.affinity import translate, rotate, scale, skew, affine_transform
|
from shapely.affinity import translate, rotate, scale, skew, affine_transform
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def svgparselength(lengthstr):
|
def svgparselength(lengthstr):
|
||||||
@@ -124,13 +125,37 @@ def svgcircle2shapely(circle):
|
|||||||
# cy = float(circle.get('cy'))
|
# cy = float(circle.get('cy'))
|
||||||
# r = float(circle.get('r'))
|
# r = float(circle.get('r'))
|
||||||
cx = svgparselength(circle.get('cx'))[0] # TODO: No units support yet
|
cx = svgparselength(circle.get('cx'))[0] # TODO: No units support yet
|
||||||
cy = svgparselength(circle.get('cy'))[1] # TODO: No units support yet
|
cy = svgparselength(circle.get('cy'))[0] # TODO: No units support yet
|
||||||
r = svgparselength(circle.get('r'))[0] # TODO: No units support yet
|
r = svgparselength(circle.get('r'))[0] # TODO: No units support yet
|
||||||
|
|
||||||
# TODO: No resolution specified.
|
# TODO: No resolution specified.
|
||||||
return Point(cx, cy).buffer(r)
|
return Point(cx, cy).buffer(r)
|
||||||
|
|
||||||
|
|
||||||
|
def svgellipse2shapely(ellipse, n_points=32):
|
||||||
|
"""
|
||||||
|
Converts an SVG ellipse into Shapely geometry
|
||||||
|
|
||||||
|
:param ellipse: Ellipse Element
|
||||||
|
:type ellipse: xml.etree.ElementTree.Element
|
||||||
|
:param n_points: Number of discrete points in output.
|
||||||
|
:return: shapely.geometry.polygon.LinearRing
|
||||||
|
"""
|
||||||
|
|
||||||
|
cx = svgparselength(ellipse.get('cx'))[0] # TODO: No units support yet
|
||||||
|
cy = svgparselength(ellipse.get('cy'))[0] # TODO: No units support yet
|
||||||
|
|
||||||
|
rx = svgparselength(ellipse.get('rx'))[0] # TODO: No units support yet
|
||||||
|
ry = svgparselength(ellipse.get('ry'))[0] # TODO: No units support yet
|
||||||
|
|
||||||
|
t = np.arange(n_points, dtype=float) / n_points
|
||||||
|
x = cx + rx * np.cos(2 * np.pi * t)
|
||||||
|
y = cy + ry * np.sin(2 * np.pi * t)
|
||||||
|
pts = [(x[i], y[i]) for i in range(n_points)]
|
||||||
|
|
||||||
|
return LinearRing(pts)
|
||||||
|
|
||||||
|
|
||||||
def getsvggeo(node):
|
def getsvggeo(node):
|
||||||
"""
|
"""
|
||||||
Extracts and flattens all geometry from an SVG node
|
Extracts and flattens all geometry from an SVG node
|
||||||
@@ -166,6 +191,11 @@ def getsvggeo(node):
|
|||||||
C = svgcircle2shapely(node)
|
C = svgcircle2shapely(node)
|
||||||
geo = [C]
|
geo = [C]
|
||||||
|
|
||||||
|
elif kind == 'ellipse':
|
||||||
|
print "***ELLIPSE***"
|
||||||
|
E = svgellipse2shapely(node)
|
||||||
|
geo = [E]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "Unknown kind:", kind
|
print "Unknown kind:", kind
|
||||||
geo = None
|
geo = None
|
||||||
|
|||||||
Reference in New Issue
Block a user