- updated the SVG parser to take into consideration the 'Close' svg element and paths that are made from a single line (we may need to switch to svgpathtools module)
This commit is contained in:
parent
9a74139497
commit
1d13b997f2
@ -5323,8 +5323,8 @@ class App(QtCore.QObject):
|
|||||||
# try to quit the Socket opened by ArgsThread class
|
# try to quit the Socket opened by ArgsThread class
|
||||||
try:
|
try:
|
||||||
self.new_launch.listener.close()
|
self.new_launch.listener.close()
|
||||||
except Exception:
|
except Exception as err:
|
||||||
pass
|
log.debug("App.quit_application() --> %s" % str(err))
|
||||||
|
|
||||||
# quit app by signalling for self.kill_app() method
|
# quit app by signalling for self.kill_app() method
|
||||||
self.close_app_signal.emit()
|
self.close_app_signal.emit()
|
||||||
|
@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing.
|
|||||||
|
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
|
1.04.2020
|
||||||
|
|
||||||
|
- updated the SVG parser to take into consideration the 'Close' svg element and paths that are made from a single line (we may need to switch to svgpathtools module)
|
||||||
|
|
||||||
30.03.2020
|
30.03.2020
|
||||||
|
|
||||||
- working to update the Paint Tool
|
- working to update the Paint Tool
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
# import xml.etree.ElementTree as ET
|
# import xml.etree.ElementTree as ET
|
||||||
from svg.path import Line, Arc, CubicBezier, QuadraticBezier, parse_path
|
from svg.path import Line, Arc, CubicBezier, QuadraticBezier, parse_path
|
||||||
from svg.path.path import Move
|
from svg.path.path import Move, Close
|
||||||
from shapely.geometry import LineString, LinearRing, MultiLineString
|
from shapely.geometry import LineString, LinearRing, MultiLineString
|
||||||
from shapely.affinity import skew, affine_transform, rotate
|
from shapely.affinity import skew, affine_transform, rotate
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -69,6 +69,7 @@ def path2shapely(path, object_type, res=1.0):
|
|||||||
geometry = []
|
geometry = []
|
||||||
geo_element = None
|
geo_element = None
|
||||||
rings = []
|
rings = []
|
||||||
|
closed = False
|
||||||
|
|
||||||
for component in path:
|
for component in path:
|
||||||
# Line
|
# Line
|
||||||
@ -88,7 +89,8 @@ def path2shapely(path, object_type, res=1.0):
|
|||||||
|
|
||||||
# How many points to use in the discrete representation.
|
# How many points to use in the discrete representation.
|
||||||
length = component.length(res / 10.0)
|
length = component.length(res / 10.0)
|
||||||
steps = int(length / res + 0.5)
|
# steps = int(length / res + 0.5)
|
||||||
|
steps = int(length) * 2
|
||||||
|
|
||||||
# solve error when step is below 1,
|
# solve error when step is below 1,
|
||||||
# it may cause other problems, but LineString needs at least two points
|
# it may cause other problems, but LineString needs at least two points
|
||||||
@ -113,7 +115,25 @@ def path2shapely(path, object_type, res=1.0):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
rings.append(points)
|
rings.append(points)
|
||||||
|
if closed is False:
|
||||||
points = []
|
points = []
|
||||||
|
else:
|
||||||
|
closed = False
|
||||||
|
start = component.start
|
||||||
|
x, y = start.real, start.imag
|
||||||
|
points = [(x, y)]
|
||||||
|
continue
|
||||||
|
|
||||||
|
closed = False
|
||||||
|
|
||||||
|
# Close
|
||||||
|
if isinstance(component, Close):
|
||||||
|
if not points:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
rings.append(points)
|
||||||
|
points = []
|
||||||
|
closed = True
|
||||||
continue
|
continue
|
||||||
log.warning("I don't know what this is: %s" % str(component))
|
log.warning("I don't know what this is: %s" % str(component))
|
||||||
continue
|
continue
|
||||||
@ -122,8 +142,12 @@ def path2shapely(path, object_type, res=1.0):
|
|||||||
|
|
||||||
if points:
|
if points:
|
||||||
rings.append(points)
|
rings.append(points)
|
||||||
|
try:
|
||||||
rings = MultiLineString(rings)
|
rings = MultiLineString(rings)
|
||||||
|
except Exception as e:
|
||||||
|
log.debug("ParseSVG.path2shapely() MString --> %s" % str(e))
|
||||||
|
return None
|
||||||
|
|
||||||
if len(rings) > 0:
|
if len(rings) > 0:
|
||||||
if len(rings) == 1 and not isinstance(rings, MultiLineString):
|
if len(rings) == 1 and not isinstance(rings, MultiLineString):
|
||||||
# Polygons are closed and require more than 2 points
|
# Polygons are closed and require more than 2 points
|
||||||
@ -139,7 +163,10 @@ def path2shapely(path, object_type, res=1.0):
|
|||||||
for line in rings:
|
for line in rings:
|
||||||
coords.append(line.coords[0])
|
coords.append(line.coords[0])
|
||||||
coords.append(line.coords[1])
|
coords.append(line.coords[1])
|
||||||
|
try:
|
||||||
geo_element = Polygon(coords)
|
geo_element = Polygon(coords)
|
||||||
|
except Exception:
|
||||||
|
geo_element = LineString(coords)
|
||||||
geometry.append(geo_element)
|
geometry.append(geo_element)
|
||||||
return geometry
|
return geometry
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user