Functional select-all for painting (#210).

This commit is contained in:
Juan Pablo Caram 2016-09-23 14:04:31 -04:00
parent 9f4ee91b0e
commit 8afb0704fd
2 changed files with 23 additions and 2 deletions

View File

@ -1308,14 +1308,18 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
#assert isinstance(app_obj, App) #assert isinstance(app_obj, App)
if self.options["paintmethod"] == "seed": if self.options["paintmethod"] == "seed":
# Type(cp) == FlatCAMRTreeStorage | None
cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]), cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]),
tooldia, overlap=overlap) tooldia, overlap=overlap)
else: else:
# Type(cp) == FlatCAMRTreeStorage | None
cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]), cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]),
tooldia, overlap=overlap) tooldia, overlap=overlap)
geo_obj.solid_geometry = list(cp.get_objects()) if cp is not None:
geo_obj.solid_geometry = list(cp.get_objects())
geo_obj.options["cnctooldia"] = tooldia geo_obj.options["cnctooldia"] = tooldia
# Experimental... # Experimental...
@ -1347,6 +1351,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
name = outname or self.options["name"] + "_paint" name = outname or self.options["name"] + "_paint"
# This is a recursive generator of individual Polygons.
# Note: Double check correct implementation. Might exit
# early if it finds something that is not a Polygon?
def recurse(geo): def recurse(geo):
try: try:
for subg in geo: for subg in geo:
@ -1368,14 +1375,17 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
for poly in recurse(self.solid_geometry): for poly in recurse(self.solid_geometry):
if self.options["paintmethod"] == "seed": if self.options["paintmethod"] == "seed":
# Type(cp) == FlatCAMRTreeStorage | None
cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]), cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]),
tooldia, overlap=overlap) tooldia, overlap=overlap)
else: else:
# Type(cp) == FlatCAMRTreeStorage | None
cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]), cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]),
tooldia, overlap=overlap) tooldia, overlap=overlap)
geo_obj.solid_geometry += list(cp.get_objects()) if cp is not None:
geo_obj.solid_geometry += list(cp.get_objects())
geo_obj.options["cnctooldia"] = tooldia geo_obj.options["cnctooldia"] = tooldia
@ -1391,6 +1401,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
app_obj.new_object("geometry", name, gen_paintarea) app_obj.new_object("geometry", name, gen_paintarea)
except Exception as e: except Exception as e:
proc.done() proc.done()
traceback.print_stack()
raise e raise e
proc.done() proc.done()

View File

@ -501,7 +501,12 @@ class Geometry(object):
geoms.get_points = get_pts geoms.get_points = get_pts
# Can only result in a Polygon or MultiPolygon # Can only result in a Polygon or MultiPolygon
# NOTE: The resulting polygon can be "empty".
current = polygon.buffer(-tooldia / 2.0) current = polygon.buffer(-tooldia / 2.0)
if current.area == 0:
# Otherwise, trying to to insert current.exterior == None
# into the FlatCAMStorage will fail.
return None
# current can be a MultiPolygon # current can be a MultiPolygon
try: try:
@ -559,6 +564,7 @@ class Geometry(object):
:param seedpoint: Shapely.geometry.Point or None :param seedpoint: Shapely.geometry.Point or None
:param overlap: Tool fraction overlap bewteen passes :param overlap: Tool fraction overlap bewteen passes
:return: List of toolpaths covering polygon. :return: List of toolpaths covering polygon.
:rtype: FlatCAMRTreeStorage | None
""" """
log.debug("camlib.clear_polygon2()") log.debug("camlib.clear_polygon2()")
@ -652,6 +658,8 @@ class Geometry(object):
:type storage: FlatCAMRTreeStorage :type storage: FlatCAMRTreeStorage
:param boundary: Polygon defining the limits of the paintable area. :param boundary: Polygon defining the limits of the paintable area.
:type boundary: Polygon :type boundary: Polygon
:param tooldia: Tool diameter.
:rtype tooldia: float
:param max_walk: Maximum allowable distance without lifting tool. :param max_walk: Maximum allowable distance without lifting tool.
:type max_walk: float or None :type max_walk: float or None
:return: Optimized geometry. :return: Optimized geometry.
@ -744,6 +752,8 @@ class Geometry(object):
Simplifies paths in the FlatCAMRTreeStorage storage by Simplifies paths in the FlatCAMRTreeStorage storage by
connecting paths that touch on their enpoints. connecting paths that touch on their enpoints.
:param storage: Storage containing the initial paths.
:rtype storage: FlatCAMRTreeStorage
:return: Simplified storage. :return: Simplified storage.
:rtype: FlatCAMRTreeStorage :rtype: FlatCAMRTreeStorage
""" """