Kaynağa Gözat

- fixed the DXF parser to work with the latest version of ezdxf module (issues for the ellipse entity and modified attribute name for the knots_values to knots)
- fixed the DXF parser to parse correctly the b-splines by not adding automatically a knot value 0f (0, 0) when the spline is not closed

Marius Stanciu 5 yıl önce
ebeveyn
işleme
249ece72e9
3 değiştirilmiş dosya ile 31 ekleme ve 15 silme
  1. 5 0
      CHANGELOG.md
  2. 17 5
      appParsers/ParseDXF.py
  3. 9 10
      appParsers/ParseDXF_Spline.py

+ 5 - 0
CHANGELOG.md

@@ -7,6 +7,11 @@ CHANGELOG for FlatCAM beta
 
 =================================================
 
+29.06.2020
+
+- fixed the DXF parser to work with the latest version of ezdxf module (issues for the ellipse entity and modified attribute name for the knots_values to knots)
+- fixed the DXF parser to parse correctly the b-splines by not adding automatically a knot value 0f (0, 0) when the spline is not closed
+
 27.06.2020
 
 - Drilling Tool - UI is working as expected; I will have to propagate the changes to other tools too, to increase likeness between different parts of the app

+ 17 - 5
appParsers/ParseDXF.py

@@ -7,6 +7,7 @@
 
 from shapely.geometry import LineString
 from shapely.affinity import rotate
+from ezdxf.math.vector import Vector as ezdxf_vector
 
 import logging
 
@@ -175,8 +176,7 @@ def dxfellipse2shapely(ellipse, ellipse_segments=100):
     ratio = ellipse.dxf.ratio
 
     points_list = []
-
-    major_axis = Vector(major_axis)
+    major_axis = Vector(list(major_axis))
 
     major_x = major_axis[0]
     major_y = major_axis[1]
@@ -248,9 +248,17 @@ def dxfsolid2shapely(solid):
 
 
 def dxfspline2shapely(spline):
-    with spline.edit_data() as spline_data:
-        ctrl_points = spline_data.control_points
-        knot_values = spline_data.knot_values
+    # for old version of ezdxf
+    # with spline.edit_data() as spline_data:
+    #     ctrl_points = spline_data.control_points
+    #     try:
+    #         # required if using old version of ezdxf
+    #         knot_values = spline_data.knot_values
+    #     except AttributeError:
+    #         knot_values = spline_data.knots
+
+    ctrl_points = spline.control_points
+    knot_values = spline.knots
     is_closed = spline.closed
     degree = spline.dxf.degree
 
@@ -322,6 +330,10 @@ def get_geo_from_insert(dxf_object, insert):
         if sx != 1 or sy != 1:
             geo = scale(geo, sx, sy)
         if phi != 0:
+            if isinstance(tr, str) and tr.lower() == 'c':
+                tr = 'center'
+            elif isinstance(tr, ezdxf_vector):
+                tr = list(tr)
             geo = rotate(geo, phi, origin=tr)
 
         geo_block_transformed.append(geo)

+ 9 - 10
appParsers/ParseDXF_Spline.py

@@ -22,18 +22,16 @@ def normalize_2(v):
 
 # ------------------------------------------------------------------------------
 # Convert a B-spline to polyline with a fixed number of segments
-#
-# FIXME to become adaptive
 # ------------------------------------------------------------------------------
 def spline2Polyline(xyz, degree, closed, segments, knots):
     """
-    :param xyz: DXF spline control points
-    :param degree: degree of the Spline curve
-    :param closed: closed Spline
-    :type closed: bool
-    :param segments: how many lines to use for Spline approximation
-    :param knots: DXF spline knots
-    :return: x,y,z coordinates (each is a list)
+    :param xyz:         DXF spline control points
+    :param degree:      degree of the Spline curve
+    :param closed:      closed Spline
+    :type closed:       bool
+    :param segments:    how many lines to use for Spline approximation
+    :param knots:       DXF spline knots
+    :return:            x,y,z coordinates (each is a list)
     """
 
     # Check if last point coincide with the first one
@@ -48,7 +46,8 @@ def spline2Polyline(xyz, degree, closed, segments, knots):
         knots = None
     else:
         # make base-1
-        knots.insert(0, 0)
+        # knots.insert(0, 0)
+        pass
 
     npts = len(xyz)