Merged in subtract-polygons (pull request #2)
rename del_polygon to subtract_polygon
This commit is contained in:
@@ -2137,7 +2137,7 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
def geocutout(name, *args):
|
def geocutout(name, *args):
|
||||||
"""
|
"""
|
||||||
cut gaps in current geometry
|
subtract gaps from geometry, this will not create new object
|
||||||
|
|
||||||
:param name:
|
:param name:
|
||||||
:param args:
|
:param args:
|
||||||
@@ -2148,6 +2148,14 @@ class App(QtCore.QObject):
|
|||||||
'gapsize': float,
|
'gapsize': float,
|
||||||
'gaps': str}
|
'gaps': str}
|
||||||
|
|
||||||
|
#way gaps wil be rendered:
|
||||||
|
# lr - left + right
|
||||||
|
# tb - top + bottom
|
||||||
|
# 4 - left + right +top + bottom
|
||||||
|
# 2lr - 2*left + 2*right
|
||||||
|
# 2tb - 2*top + 2*bottom
|
||||||
|
# 8 - 2*left + 2*right +2*top + 2*bottom
|
||||||
|
|
||||||
for key in kwa:
|
for key in kwa:
|
||||||
if key not in types:
|
if key not in types:
|
||||||
return 'Unknown parameter: %s' % key
|
return 'Unknown parameter: %s' % key
|
||||||
@@ -2159,15 +2167,23 @@ class App(QtCore.QObject):
|
|||||||
return "Could not retrieve object: %s" % name
|
return "Could not retrieve object: %s" % name
|
||||||
|
|
||||||
|
|
||||||
|
#get min and max data for each object as we just cut rectangles across X or Y
|
||||||
xmin, ymin, xmax, ymax = obj.bounds()
|
xmin, ymin, xmax, ymax = obj.bounds()
|
||||||
px = 0.5 * (xmin + xmax)
|
px = 0.5 * (xmin + xmax)
|
||||||
py = 0.5 * (ymin + ymax)
|
py = 0.5 * (ymin + ymax)
|
||||||
|
lenghtx = (xmax - xmin)
|
||||||
|
lenghty = (ymax - ymin)
|
||||||
gapsize = kwa['gapsize']+kwa['dia']/2
|
gapsize = kwa['gapsize']+kwa['dia']/2
|
||||||
|
if kwa['gaps'] == '8' or kwa['gaps']=='2lr':
|
||||||
|
subtract_rectangle(name,xmin-gapsize,py-gapsize+lenghty/4,xmax+gapsize,py+gapsize+lenghty/4)
|
||||||
|
subtract_rectangle(name,xmin-gapsize,py-gapsize-lenghty/4,xmax+gapsize,py+gapsize-lenghty/4)
|
||||||
|
if kwa['gaps'] == '8' or kwa['gaps']=='2tb':
|
||||||
|
subtract_rectangle(name,px-gapsize+lenghtx/4,ymin-gapsize,px+gapsize+lenghtx/4,ymax+gapsize)
|
||||||
|
subtract_rectangle(name,px-gapsize-lenghtx/4,ymin-gapsize,px+gapsize-lenghtx/4,ymax+gapsize)
|
||||||
if kwa['gaps'] == '4' or kwa['gaps']=='lr':
|
if kwa['gaps'] == '4' or kwa['gaps']=='lr':
|
||||||
del_rectangle(name,xmin-gapsize,py-gapsize,xmax+gapsize,py+gapsize)
|
subtract_rectangle(name,xmin-gapsize,py-gapsize,xmax+gapsize,py+gapsize)
|
||||||
if kwa['gaps'] == '4' or kwa['gaps']=='tb':
|
if kwa['gaps'] == '4' or kwa['gaps']=='tb':
|
||||||
del_rectangle(name,px-gapsize,ymin-gapsize,px+gapsize,ymax+gapsize)
|
subtract_rectangle(name,px-gapsize,ymin-gapsize,px+gapsize,ymax+gapsize)
|
||||||
return 'Ok'
|
return 'Ok'
|
||||||
|
|
||||||
def mirror(name, *args):
|
def mirror(name, *args):
|
||||||
@@ -2718,7 +2734,7 @@ class App(QtCore.QObject):
|
|||||||
return add_poly(obj_name, botleft_x, botleft_y, botleft_x, topright_y,
|
return add_poly(obj_name, botleft_x, botleft_y, botleft_x, topright_y,
|
||||||
topright_x, topright_y, topright_x, botleft_y)
|
topright_x, topright_y, topright_x, botleft_y)
|
||||||
|
|
||||||
def del_poly(obj_name, *args):
|
def subtract_poly(obj_name, *args):
|
||||||
if len(args) % 2 != 0:
|
if len(args) % 2 != 0:
|
||||||
return "Incomplete coordinate."
|
return "Incomplete coordinate."
|
||||||
|
|
||||||
@@ -2731,19 +2747,13 @@ class App(QtCore.QObject):
|
|||||||
if obj is None:
|
if obj is None:
|
||||||
return "Object not found: %s" % obj_name
|
return "Object not found: %s" % obj_name
|
||||||
|
|
||||||
def init_obj_me(init_obj, app):
|
obj.subtract_polygon(points)
|
||||||
assert isinstance(init_obj, FlatCAMGeometry)
|
obj.plot()
|
||||||
init_obj.solid_geometry=cascaded_union(diff)
|
|
||||||
|
|
||||||
diff= obj.del_polygon(points)
|
return "OK."
|
||||||
try:
|
|
||||||
delete(obj_name)
|
|
||||||
obj.app.new_object("geometry", obj_name, init_obj_me)
|
|
||||||
except Exception as e:
|
|
||||||
return "Failed: %s" % str(e)
|
|
||||||
|
|
||||||
def del_rectangle(obj_name, botleft_x, botleft_y, topright_x, topright_y):
|
def subtract_rectangle(obj_name, botleft_x, botleft_y, topright_x, topright_y):
|
||||||
return del_poly(obj_name, botleft_x, botleft_y, botleft_x, topright_y,
|
return subtract_poly(obj_name, botleft_x, botleft_y, botleft_x, topright_y,
|
||||||
topright_x, topright_y, topright_x, botleft_y)
|
topright_x, topright_y, topright_x, botleft_y)
|
||||||
|
|
||||||
def add_circle(obj_name, center_x, center_y, radius):
|
def add_circle(obj_name, center_x, center_y, radius):
|
||||||
@@ -3091,8 +3101,8 @@ class App(QtCore.QObject):
|
|||||||
},
|
},
|
||||||
'geocutout': {
|
'geocutout': {
|
||||||
'fcn': geocutout,
|
'fcn': geocutout,
|
||||||
'help': "Cut holding gaps closed geometry.\n" +
|
'help': "Cut holding gaps from geometry.\n" +
|
||||||
"> geocutout <name> [-dia <3.0 (float)>] [-margin <0.0 (float)>] [-gapsize <0.5 (float)>] [-gaps <lr (4|tb|lr)>]\n" +
|
"> geocutout <name> [-dia <3.0 (float)>] [-margin <0.0 (float)>] [-gapsize <0.5 (float)>] [-gaps <lr (8|4|tb|lr|2tb|2lr)>]\n" +
|
||||||
" name: Name of the geometry object\n" +
|
" name: Name of the geometry object\n" +
|
||||||
" dia: Tool diameter\n" +
|
" dia: Tool diameter\n" +
|
||||||
" margin: Margin over bounds\n" +
|
" margin: Margin over bounds\n" +
|
||||||
@@ -3245,11 +3255,11 @@ class App(QtCore.QObject):
|
|||||||
' name: Name of the geometry object to which to append the polygon.\n' +
|
' name: Name of the geometry object to which to append the polygon.\n' +
|
||||||
' xi, yi: Coordinates of points in the polygon.'
|
' xi, yi: Coordinates of points in the polygon.'
|
||||||
},
|
},
|
||||||
'del_poly': {
|
'subtract_poly': {
|
||||||
'fcn': del_poly,
|
'fcn': subtract_poly,
|
||||||
'help': ' - Remove a polygon from the given Geometry object.\n' +
|
'help': 'Subtract polygon from the given Geometry object.\n' +
|
||||||
'> del_poly <name> <x0> <y0> <x1> <y1> <x2> <y2> [x3 y3 [...]]\n' +
|
'> subtract_poly <name> <x0> <y0> <x1> <y1> <x2> <y2> [x3 y3 [...]]\n' +
|
||||||
' name: Name of the geometry object to which to remove the polygon.\n' +
|
' name: Name of the geometry object, which will be sutracted.\n' +
|
||||||
' xi, yi: Coordinates of points in the polygon.'
|
' xi, yi: Coordinates of points in the polygon.'
|
||||||
},
|
},
|
||||||
'delete': {
|
'delete': {
|
||||||
@@ -3295,11 +3305,11 @@ class App(QtCore.QObject):
|
|||||||
" rows: number of rows\n"+
|
" rows: number of rows\n"+
|
||||||
" outname: Name of the new geometry object."
|
" outname: Name of the new geometry object."
|
||||||
},
|
},
|
||||||
'del_rect': {
|
'subtract_rect': {
|
||||||
'fcn': del_rectangle,
|
'fcn': subtract_rectangle,
|
||||||
'help': 'Delete a rectange from the given Geometry object.\n' +
|
'help': 'Subtract rectange from the given Geometry object.\n' +
|
||||||
'> del_rect <name> <botleft_x> <botleft_y> <topright_x> <topright_y>\n' +
|
'> subtract_rect <name> <botleft_x> <botleft_y> <topright_x> <topright_y>\n' +
|
||||||
' name: Name of the geometry object to which to remove the rectangle.\n' +
|
' name: Name of the geometry object, which will be subtracted.\n' +
|
||||||
' botleft_x, botleft_y: Coordinates of the bottom left corner.\n' +
|
' botleft_x, botleft_y: Coordinates of the bottom left corner.\n' +
|
||||||
' topright_x, topright_y Coordinates of the top right corner.'
|
' topright_x, topright_y Coordinates of the top right corner.'
|
||||||
},
|
},
|
||||||
|
|||||||
10
camlib.py
10
camlib.py
@@ -136,17 +136,17 @@ class Geometry(object):
|
|||||||
log.error("Failed to run union on polygons.")
|
log.error("Failed to run union on polygons.")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def del_polygon(self, points):
|
def subtract_polygon(self, points):
|
||||||
"""
|
"""
|
||||||
Delete a polygon from the object
|
Subtract polygon from the given object. This only operates on the paths in the original geometry, i.e. it converts polygons into paths.
|
||||||
|
|
||||||
:param points: The vertices of the polygon.
|
:param points: The vertices of the polygon.
|
||||||
:return: None
|
:return: none
|
||||||
"""
|
"""
|
||||||
if self.solid_geometry is None:
|
if self.solid_geometry is None:
|
||||||
self.solid_geometry = []
|
self.solid_geometry = []
|
||||||
|
|
||||||
|
#pathonly should be allways True, otherwise polygons are not subtracted
|
||||||
flat_geometry = self.flatten(pathonly=True)
|
flat_geometry = self.flatten(pathonly=True)
|
||||||
log.debug("%d paths" % len(flat_geometry))
|
log.debug("%d paths" % len(flat_geometry))
|
||||||
polygon=Polygon(points)
|
polygon=Polygon(points)
|
||||||
@@ -157,7 +157,7 @@ class Geometry(object):
|
|||||||
diffs.append(target.difference(toolgeo))
|
diffs.append(target.difference(toolgeo))
|
||||||
else:
|
else:
|
||||||
log.warning("Not implemented.")
|
log.warning("Not implemented.")
|
||||||
return cascaded_union(diffs)
|
self.solid_geometry=cascaded_union(diffs)
|
||||||
|
|
||||||
def bounds(self):
|
def bounds(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user