|
@@ -92,8 +92,11 @@ class Geometry(object):
|
|
|
# Final geometry: MultiPolygon or list (of geometry constructs)
|
|
# Final geometry: MultiPolygon or list (of geometry constructs)
|
|
|
self.solid_geometry = None
|
|
self.solid_geometry = None
|
|
|
|
|
|
|
|
|
|
+ # Final geometry: MultiLineString or list (of LineString or Points)
|
|
|
|
|
+ self.follow_geometry = None
|
|
|
|
|
+
|
|
|
# Attributes to be included in serialization
|
|
# Attributes to be included in serialization
|
|
|
- self.ser_attrs = ["units", 'solid_geometry']
|
|
|
|
|
|
|
+ self.ser_attrs = ["units", 'solid_geometry', 'follow_geometry']
|
|
|
|
|
|
|
|
# Flattened geometry (list of paths only)
|
|
# Flattened geometry (list of paths only)
|
|
|
self.flat_geometry = []
|
|
self.flat_geometry = []
|
|
@@ -500,7 +503,7 @@ class Geometry(object):
|
|
|
#
|
|
#
|
|
|
# return self.flat_geometry, self.flat_geometry_rtree
|
|
# return self.flat_geometry, self.flat_geometry_rtree
|
|
|
|
|
|
|
|
- def isolation_geometry(self, offset, iso_type=2, corner=None):
|
|
|
|
|
|
|
+ def isolation_geometry(self, offset, iso_type=2, corner=None, follow=None):
|
|
|
"""
|
|
"""
|
|
|
Creates contours around geometry at a given
|
|
Creates contours around geometry at a given
|
|
|
offset distance.
|
|
offset distance.
|
|
@@ -542,16 +545,24 @@ class Geometry(object):
|
|
|
# the previously commented block is replaced with this block - regression - to solve the bug with multiple
|
|
# the previously commented block is replaced with this block - regression - to solve the bug with multiple
|
|
|
# isolation passes cutting from the copper features
|
|
# isolation passes cutting from the copper features
|
|
|
if offset == 0:
|
|
if offset == 0:
|
|
|
- geo_iso = self.solid_geometry
|
|
|
|
|
|
|
+ if follow:
|
|
|
|
|
+ geo_iso = self.follow_geometry
|
|
|
|
|
+ else:
|
|
|
|
|
+ geo_iso = self.solid_geometry
|
|
|
else:
|
|
else:
|
|
|
- if corner is None:
|
|
|
|
|
- geo_iso = self.solid_geometry.buffer(offset, int(int(self.geo_steps_per_circle) / 4))
|
|
|
|
|
|
|
+ if follow:
|
|
|
|
|
+ geo_iso = self.follow_geometry
|
|
|
else:
|
|
else:
|
|
|
- geo_iso = self.solid_geometry.buffer(offset, int(int(self.geo_steps_per_circle) / 4), join_style=corner)
|
|
|
|
|
|
|
+ if corner is None:
|
|
|
|
|
+ geo_iso = self.solid_geometry.buffer(offset, int(int(self.geo_steps_per_circle) / 4))
|
|
|
|
|
+ else:
|
|
|
|
|
+ geo_iso = self.solid_geometry.buffer(offset, int(int(self.geo_steps_per_circle) / 4),
|
|
|
|
|
+ join_style=corner)
|
|
|
|
|
|
|
|
# end of replaced block
|
|
# end of replaced block
|
|
|
-
|
|
|
|
|
- if iso_type == 2:
|
|
|
|
|
|
|
+ if follow:
|
|
|
|
|
+ return geo_iso
|
|
|
|
|
+ elif iso_type == 2:
|
|
|
return geo_iso
|
|
return geo_iso
|
|
|
elif iso_type == 0:
|
|
elif iso_type == 0:
|
|
|
return self.get_exteriors(geo_iso)
|
|
return self.get_exteriors(geo_iso)
|
|
@@ -1889,8 +1900,12 @@ class Gerber (Geometry):
|
|
|
# Initialize parent
|
|
# Initialize parent
|
|
|
Geometry.__init__(self, geo_steps_per_circle=int(steps_per_circle))
|
|
Geometry.__init__(self, geo_steps_per_circle=int(steps_per_circle))
|
|
|
|
|
|
|
|
|
|
+ # will store the Gerber geometry's as solids
|
|
|
self.solid_geometry = Polygon()
|
|
self.solid_geometry = Polygon()
|
|
|
|
|
|
|
|
|
|
+ # will store the Gerber geometry's as paths
|
|
|
|
|
+ self.follow_geometry = []
|
|
|
|
|
+
|
|
|
# Number format
|
|
# Number format
|
|
|
self.int_digits = 3
|
|
self.int_digits = 3
|
|
|
"""Number of integer digits in Gerber numbers. Used during parsing."""
|
|
"""Number of integer digits in Gerber numbers. Used during parsing."""
|
|
@@ -2113,10 +2128,10 @@ class Gerber (Geometry):
|
|
|
yield line
|
|
yield line
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
- self.parse_lines(line_generator(), follow=follow)
|
|
|
|
|
|
|
+ self.parse_lines(line_generator())
|
|
|
|
|
|
|
|
#@profile
|
|
#@profile
|
|
|
- def parse_lines(self, glines, follow=False):
|
|
|
|
|
|
|
+ def parse_lines(self, glines):
|
|
|
"""
|
|
"""
|
|
|
Main Gerber parser. Reads Gerber and populates ``self.paths``, ``self.apertures``,
|
|
Main Gerber parser. Reads Gerber and populates ``self.paths``, ``self.apertures``,
|
|
|
``self.flashes``, ``self.regions`` and ``self.units``.
|
|
``self.flashes``, ``self.regions`` and ``self.units``.
|
|
@@ -2143,6 +2158,9 @@ class Gerber (Geometry):
|
|
|
# applying a union for every new polygon.
|
|
# applying a union for every new polygon.
|
|
|
poly_buffer = []
|
|
poly_buffer = []
|
|
|
|
|
|
|
|
|
|
+ # store here the follow geometry
|
|
|
|
|
+ follow_buffer = []
|
|
|
|
|
+
|
|
|
last_path_aperture = None
|
|
last_path_aperture = None
|
|
|
current_aperture = None
|
|
current_aperture = None
|
|
|
|
|
|
|
@@ -2208,10 +2226,11 @@ class Gerber (Geometry):
|
|
|
# --- Buffered ----
|
|
# --- Buffered ----
|
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
|
|
|
|
@@ -2222,9 +2241,14 @@ class Gerber (Geometry):
|
|
|
# TODO: Remove when bug fixed
|
|
# TODO: Remove when bug fixed
|
|
|
if len(poly_buffer) > 0:
|
|
if len(poly_buffer) > 0:
|
|
|
if current_polarity == 'D':
|
|
if current_polarity == 'D':
|
|
|
|
|
+ self.follow_geometry = self.solid_geometry.union(cascaded_union(follow_buffer))
|
|
|
self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer))
|
|
self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer))
|
|
|
|
|
+
|
|
|
else:
|
|
else:
|
|
|
- self.solid_geometry = self.solid_geometry.difference(cascaded_union(poly_buffer))
|
|
|
|
|
|
|
+ self.follow_geometry = self.solid_geometry.difference(cascaded_union(follow_buffer))
|
|
|
|
|
+ self.solid_geometry = self.solid_geometry.union(cascaded_union(poly_buffer))
|
|
|
|
|
+
|
|
|
|
|
+ follow_buffer = []
|
|
|
poly_buffer = []
|
|
poly_buffer = []
|
|
|
|
|
|
|
|
current_polarity = match.group(1)
|
|
current_polarity = match.group(1)
|
|
@@ -2405,10 +2429,11 @@ class Gerber (Geometry):
|
|
|
# --- Buffered ----
|
|
# --- Buffered ----
|
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
|
|
|
|
@@ -2424,10 +2449,11 @@ class Gerber (Geometry):
|
|
|
## --- Buffered ---
|
|
## --- Buffered ---
|
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width/1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ geo = LineString(path).buffer(width/1.999, int(self.steps_per_circle / 4))
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
|
|
|
|
@@ -2445,6 +2471,7 @@ class Gerber (Geometry):
|
|
|
if current_operation_code == 2:
|
|
if current_operation_code == 2:
|
|
|
if geo:
|
|
if geo:
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
@@ -2464,15 +2491,14 @@ class Gerber (Geometry):
|
|
|
# "aperture": last_path_aperture})
|
|
# "aperture": last_path_aperture})
|
|
|
|
|
|
|
|
# --- Buffered ---
|
|
# --- Buffered ---
|
|
|
- if follow:
|
|
|
|
|
- region = Polygon()
|
|
|
|
|
- else:
|
|
|
|
|
- region = Polygon(path)
|
|
|
|
|
|
|
|
|
|
- if not region.is_valid:
|
|
|
|
|
- if not follow:
|
|
|
|
|
- region = region.buffer(0, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ region = Polygon()
|
|
|
|
|
+ if not region.is_empty:
|
|
|
|
|
+ follow_buffer.append(region)
|
|
|
|
|
|
|
|
|
|
+ region = Polygon(path)
|
|
|
|
|
+ if not region.is_valid:
|
|
|
|
|
+ region = region.buffer(0, int(self.steps_per_circle / 4))
|
|
|
if not region.is_empty:
|
|
if not region.is_empty:
|
|
|
poly_buffer.append(region)
|
|
poly_buffer.append(region)
|
|
|
|
|
|
|
@@ -2529,7 +2555,7 @@ class Gerber (Geometry):
|
|
|
if path[-1] != [linear_x, linear_y]:
|
|
if path[-1] != [linear_x, linear_y]:
|
|
|
path.append([linear_x, linear_y])
|
|
path.append([linear_x, linear_y])
|
|
|
|
|
|
|
|
- if follow == 0 and making_region is False:
|
|
|
|
|
|
|
+ if making_region is False:
|
|
|
# if the aperture is rectangle then add a rectangular shape having as parameters the
|
|
# if the aperture is rectangle then add a rectangular shape having as parameters the
|
|
|
# coordinates of the start and end point and also the width and height
|
|
# coordinates of the start and end point and also the width and height
|
|
|
# of the 'R' aperture
|
|
# of the 'R' aperture
|
|
@@ -2555,29 +2581,35 @@ class Gerber (Geometry):
|
|
|
geo = None
|
|
geo = None
|
|
|
|
|
|
|
|
## --- BUFFERED ---
|
|
## --- BUFFERED ---
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths only
|
|
|
|
|
+ if making_region:
|
|
|
|
|
+ geo = Polygon()
|
|
|
|
|
+ else:
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ try:
|
|
|
|
|
+ if self.apertures[last_path_aperture]["type"] != 'R':
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+ except:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
if making_region:
|
|
if making_region:
|
|
|
- if follow:
|
|
|
|
|
- geo = Polygon()
|
|
|
|
|
- else:
|
|
|
|
|
- elem = [linear_x, linear_y]
|
|
|
|
|
- if elem != path[-1]:
|
|
|
|
|
- path.append([linear_x, linear_y])
|
|
|
|
|
- try:
|
|
|
|
|
- geo = Polygon(path)
|
|
|
|
|
- except ValueError:
|
|
|
|
|
- log.warning("Problem %s %s" % (gline, line_num))
|
|
|
|
|
- self.app.inform.emit("[ERROR] Region does not have enough points. "
|
|
|
|
|
- "File will be processed but there are parser errors. "
|
|
|
|
|
- "Line number: %s" % str(line_num))
|
|
|
|
|
|
|
+ elem = [linear_x, linear_y]
|
|
|
|
|
+ if elem != path[-1]:
|
|
|
|
|
+ path.append([linear_x, linear_y])
|
|
|
|
|
+ try:
|
|
|
|
|
+ geo = Polygon(path)
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ log.warning("Problem %s %s" % (gline, line_num))
|
|
|
|
|
+ self.app.inform.emit("[ERROR] Region does not have enough points. "
|
|
|
|
|
+ "File will be processed but there are parser errors. "
|
|
|
|
|
+ "Line number: %s" % str(line_num))
|
|
|
else:
|
|
else:
|
|
|
if last_path_aperture is None:
|
|
if last_path_aperture is None:
|
|
|
log.warning("No aperture defined for curent path. (%d)" % line_num)
|
|
log.warning("No aperture defined for curent path. (%d)" % line_num)
|
|
|
width = self.apertures[last_path_aperture]["size"] # TODO: WARNING this should fail!
|
|
width = self.apertures[last_path_aperture]["size"] # TODO: WARNING this should fail!
|
|
|
- #log.debug("Line %d: Setting aperture to %s before buffering." % (line_num, last_path_aperture))
|
|
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
if self.apertures[last_path_aperture]["type"] != 'R':
|
|
if self.apertures[last_path_aperture]["type"] != 'R':
|
|
@@ -2600,19 +2632,23 @@ class Gerber (Geometry):
|
|
|
# Create path draw so far.
|
|
# Create path draw so far.
|
|
|
if len(path) > 1:
|
|
if len(path) > 1:
|
|
|
# --- Buffered ----
|
|
# --- Buffered ----
|
|
|
- width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
|
|
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ try:
|
|
|
|
|
+ if self.apertures[current_aperture]["type"] != 'R':
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+ except:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
|
|
+ width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
+ geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
try:
|
|
try:
|
|
|
if self.apertures[current_aperture]["type"] != 'R':
|
|
if self.apertures[current_aperture]["type"] != 'R':
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
- else:
|
|
|
|
|
- pass
|
|
|
|
|
except:
|
|
except:
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
|
|
|
|
@@ -2621,11 +2657,12 @@ class Gerber (Geometry):
|
|
|
|
|
|
|
|
# --- BUFFERED ---
|
|
# --- BUFFERED ---
|
|
|
# Draw the flash
|
|
# Draw the flash
|
|
|
- if follow:
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths
|
|
|
|
|
+ follow_buffer.append(Point([linear_x, linear_y]))
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
flash = Gerber.create_flash_geometry(
|
|
flash = Gerber.create_flash_geometry(
|
|
|
- Point(
|
|
|
|
|
- [linear_x, linear_y]),
|
|
|
|
|
|
|
+ Point( [linear_x, linear_y]),
|
|
|
self.apertures[current_aperture],
|
|
self.apertures[current_aperture],
|
|
|
int(self.steps_per_circle)
|
|
int(self.steps_per_circle)
|
|
|
)
|
|
)
|
|
@@ -2711,10 +2748,13 @@ class Gerber (Geometry):
|
|
|
# --- BUFFERED ---
|
|
# --- BUFFERED ---
|
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
|
|
|
|
|
|
- if follow:
|
|
|
|
|
- buffered = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- buffered = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
|
|
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
|
|
+ buffered = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
|
|
|
if not buffered.is_empty:
|
|
if not buffered.is_empty:
|
|
|
poly_buffer.append(buffered)
|
|
poly_buffer.append(buffered)
|
|
|
|
|
|
|
@@ -2833,19 +2873,24 @@ class Gerber (Geometry):
|
|
|
else:
|
|
else:
|
|
|
# EOF, create shapely LineString if something still in path
|
|
# EOF, create shapely LineString if something still in path
|
|
|
## --- Buffered ---
|
|
## --- Buffered ---
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths
|
|
|
|
|
+ geo = LineString(path)
|
|
|
|
|
+ if not geo.is_empty:
|
|
|
|
|
+ follow_buffer.append(geo)
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
width = self.apertures[last_path_aperture]["size"]
|
|
|
- if follow:
|
|
|
|
|
- geo = LineString(path)
|
|
|
|
|
- else:
|
|
|
|
|
- geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
|
|
|
|
+ geo = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4))
|
|
|
if not geo.is_empty:
|
|
if not geo.is_empty:
|
|
|
poly_buffer.append(geo)
|
|
poly_buffer.append(geo)
|
|
|
|
|
|
|
|
# --- Apply buffer ---
|
|
# --- Apply buffer ---
|
|
|
- if follow:
|
|
|
|
|
- self.solid_geometry = poly_buffer
|
|
|
|
|
- return
|
|
|
|
|
|
|
|
|
|
|
|
+ # this treats the case when we are storing geometry as paths
|
|
|
|
|
+ self.follow_geometry = follow_buffer
|
|
|
|
|
+
|
|
|
|
|
+ # this treats the case when we are storing geometry as solids
|
|
|
log.warning("Joining %d polygons." % len(poly_buffer))
|
|
log.warning("Joining %d polygons." % len(poly_buffer))
|
|
|
|
|
|
|
|
if len(poly_buffer) == 0:
|
|
if len(poly_buffer) == 0:
|