Added "connect" option for painting polygons.
This commit is contained in:
parent
0b26a90175
commit
f6d9901365
|
@ -651,7 +651,9 @@ class GeometryOptionsGroupUI(OptionsGroupUI):
|
|||
)
|
||||
self.layout.addWidget(self.plot_cb)
|
||||
|
||||
# ------------------------------
|
||||
## Create CNC Job
|
||||
# ------------------------------
|
||||
self.cncjob_label = QtGui.QLabel('<b>Create CNC Job:</b>')
|
||||
self.cncjob_label.setToolTip(
|
||||
"Create a CNC Job object\n"
|
||||
|
@ -711,7 +713,9 @@ class GeometryOptionsGroupUI(OptionsGroupUI):
|
|||
self.cncspindlespeed_entry = IntEntry(allow_empty=True)
|
||||
grid1.addWidget(self.cncspindlespeed_entry, 4, 1)
|
||||
|
||||
# ------------------------------
|
||||
## Paint area
|
||||
# ------------------------------
|
||||
self.paint_label = QtGui.QLabel('<b>Paint Area:</b>')
|
||||
self.paint_label.setToolTip(
|
||||
"Creates tool paths to cover the\n"
|
||||
|
@ -756,19 +760,44 @@ class GeometryOptionsGroupUI(OptionsGroupUI):
|
|||
self.paintmargin_entry = LengthEntry()
|
||||
grid2.addWidget(self.paintmargin_entry, 2, 1)
|
||||
|
||||
# Method
|
||||
methodlabel = QtGui.QLabel('Method:')
|
||||
methodlabel.setToolTip(
|
||||
"Algorithm to paint the polygon:<BR>"
|
||||
"<B>Standard</B>: Fixed step inwards.<BR>"
|
||||
"<B>Seed-based</B>: Outwards from seed."
|
||||
)
|
||||
grid2.addWidget(methodlabel, 3, 0)
|
||||
self.paintmethod_combo = RadioSet([
|
||||
{"label": "Standard", "value": "standard"},
|
||||
{"label": "Seed-based", "value": "seed"},
|
||||
{"label": "Straight lines", "value": "lines"}
|
||||
], orientation='vertical')
|
||||
grid2.addWidget(self.paintmethod_combo, 3, 1)
|
||||
|
||||
# Connect lines
|
||||
pathconnectlabel = QtGui.QLabel("Connect:")
|
||||
pathconnectlabel.setToolTip(
|
||||
"Draw lines between resulting\n"
|
||||
"segments to minimize tool lifts."
|
||||
)
|
||||
grid2.addWidget(pathconnectlabel, 4, 0)
|
||||
self.pathconnect_cb = FCCheckBox()
|
||||
grid2.addWidget(self.pathconnect_cb, 4, 1)
|
||||
|
||||
# Polygon selection
|
||||
selectlabel = QtGui.QLabel('Selection:')
|
||||
selectlabel.setToolTip(
|
||||
"How to select the polygons to paint."
|
||||
)
|
||||
grid2.addWidget(selectlabel, 3, 0)
|
||||
grid2.addWidget(selectlabel, 5, 0)
|
||||
# grid3 = QtGui.QGridLayout()
|
||||
self.selectmethod_combo = RadioSet([
|
||||
{"label": "Single", "value": "single"},
|
||||
{"label": "All", "value": "all"},
|
||||
# {"label": "Rectangle", "value": "rectangle"}
|
||||
])
|
||||
grid2.addWidget(self.selectmethod_combo, 3, 1)
|
||||
grid2.addWidget(self.selectmethod_combo, 5, 1)
|
||||
|
||||
|
||||
class CNCJobOptionsGroupUI(OptionsGroupUI):
|
||||
|
|
|
@ -1210,6 +1210,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
"paintoverlap": 0.15,
|
||||
"paintmargin": 0.01,
|
||||
"paintmethod": "standard",
|
||||
"pathconnect": True,
|
||||
"multidepth": False,
|
||||
"depthperpass": 0.002,
|
||||
"selectmethod": "single"
|
||||
|
@ -1242,6 +1243,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
"paintoverlap": self.ui.paintoverlap_entry,
|
||||
"paintmargin": self.ui.paintmargin_entry,
|
||||
"paintmethod": self.ui.paintmethod_combo,
|
||||
"pathconnect": self.ui.pathconnect_cb,
|
||||
"multidepth": self.ui.mpass_cb,
|
||||
"depthperpass": self.ui.maxdepth_entry,
|
||||
"selectmethod": self.ui.selectmethod_combo
|
||||
|
@ -1259,7 +1261,8 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
overlap = self.options["paintoverlap"]
|
||||
|
||||
if self.options["selectmethod"] == "all":
|
||||
self.paint_poly_all(tooldia, overlap)
|
||||
self.paint_poly_all(tooldia, overlap,
|
||||
connect=self.option["pathconnect"])
|
||||
return
|
||||
|
||||
if self.options["selectmethod"] == "single":
|
||||
|
@ -1270,11 +1273,13 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
self.app.info("Painting polygon...")
|
||||
self.app.plotcanvas.mpl_disconnect(subscription)
|
||||
point = [event.xdata, event.ydata]
|
||||
self.paint_poly_single_click(point, tooldia, overlap)
|
||||
self.paint_poly_single_click(point, tooldia, overlap,
|
||||
connect=self.options["pathconnect"])
|
||||
|
||||
subscription = self.app.plotcanvas.mpl_connect('button_press_event', doit)
|
||||
|
||||
def paint_poly_single_click(self, inside_pt, tooldia, overlap, outname=None):
|
||||
def paint_poly_single_click(self, inside_pt, tooldia, overlap,
|
||||
outname=None, connect=True):
|
||||
"""
|
||||
Paints a polygon selected by clicking on its interior.
|
||||
|
||||
|
@ -1310,16 +1315,16 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
if self.options["paintmethod"] == "seed":
|
||||
# Type(cp) == FlatCAMRTreeStorage | None
|
||||
cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]),
|
||||
tooldia, overlap=overlap)
|
||||
tooldia, overlap=overlap, connect=connect)
|
||||
|
||||
elif self.options["paintmethod"] == "lines":
|
||||
# Type(cp) == FlatCAMRTreeStorage | None
|
||||
cp = self.clear_polygon3(poly.buffer(-self.options["paintmargin"]),
|
||||
tooldia, overlap=overlap)
|
||||
tooldia, overlap=overlap, connect=connect)
|
||||
else:
|
||||
# Type(cp) == FlatCAMRTreeStorage | None
|
||||
cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]),
|
||||
tooldia, overlap=overlap)
|
||||
tooldia, overlap=overlap, connect=connect)
|
||||
|
||||
if cp is not None:
|
||||
geo_obj.solid_geometry = list(cp.get_objects())
|
||||
|
|
|
@ -16,6 +16,8 @@ class RadioSet(QtGui.QWidget):
|
|||
* 'value': The value returned is selected
|
||||
|
||||
:param choices: List of choices. See description.
|
||||
:param orientation: 'horizontal' (default) of 'vertical'.
|
||||
:param parent: Qt parent widget.
|
||||
:type choices: list
|
||||
"""
|
||||
super(RadioSet, self).__init__(parent)
|
||||
|
|
17
ObjectUI.py
17
ObjectUI.py
|
@ -385,6 +385,7 @@ class GeometryObjectUI(ObjectUI):
|
|||
|
||||
# Method
|
||||
methodlabel = QtGui.QLabel('Method:')
|
||||
methodlabel.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
|
||||
methodlabel.setToolTip(
|
||||
"Algorithm to paint the polygon:<BR>"
|
||||
"<B>Standard</B>: Fixed step inwards.<BR>"
|
||||
|
@ -395,22 +396,32 @@ class GeometryObjectUI(ObjectUI):
|
|||
{"label": "Standard", "value": "standard"},
|
||||
{"label": "Seed-based", "value": "seed"},
|
||||
{"label": "Straight lines", "value": "lines"}
|
||||
])
|
||||
], orientation='vertical')
|
||||
grid2.addWidget(self.paintmethod_combo, 3, 1)
|
||||
|
||||
# Connect lines
|
||||
pathconnectlabel = QtGui.QLabel("Connect:")
|
||||
pathconnectlabel.setToolTip(
|
||||
"Draw lines between resulting\n"
|
||||
"segments to minimize tool lifts."
|
||||
)
|
||||
grid2.addWidget(pathconnectlabel, 4, 0)
|
||||
self.pathconnect_cb = FCCheckBox()
|
||||
grid2.addWidget(self.pathconnect_cb, 4, 1)
|
||||
|
||||
# Polygon selection
|
||||
selectlabel = QtGui.QLabel('Selection:')
|
||||
selectlabel.setToolTip(
|
||||
"How to select the polygons to paint."
|
||||
)
|
||||
grid2.addWidget(selectlabel, 4, 0)
|
||||
grid2.addWidget(selectlabel, 5, 0)
|
||||
#grid3 = QtGui.QGridLayout()
|
||||
self.selectmethod_combo = RadioSet([
|
||||
{"label": "Single", "value": "single"},
|
||||
{"label": "All", "value": "all"},
|
||||
#{"label": "Rectangle", "value": "rectangle"}
|
||||
])
|
||||
grid2.addWidget(self.selectmethod_combo, 4, 1)
|
||||
grid2.addWidget(self.selectmethod_combo, 5, 1)
|
||||
|
||||
# GO Button
|
||||
self.generate_paint_button = QtGui.QPushButton('Generate')
|
||||
|
|
|
@ -475,7 +475,7 @@ class Geometry(object):
|
|||
return boundary.difference(self.solid_geometry)
|
||||
|
||||
@staticmethod
|
||||
def clear_polygon(polygon, tooldia, overlap=0.15):
|
||||
def clear_polygon(polygon, tooldia, overlap=0.15, connect=True):
|
||||
"""
|
||||
Creates geometry inside a polygon for a tool to cover
|
||||
the whole area.
|
||||
|
@ -543,13 +543,14 @@ class Geometry(object):
|
|||
break
|
||||
|
||||
# Optimization: Reduce lifts
|
||||
if connect:
|
||||
log.debug("Reducing tool lifts...")
|
||||
geoms = Geometry.paint_connect(geoms, polygon, tooldia)
|
||||
|
||||
return geoms
|
||||
|
||||
@staticmethod
|
||||
def clear_polygon2(polygon, tooldia, seedpoint=None, overlap=0.15):
|
||||
def clear_polygon2(polygon, tooldia, seedpoint=None, overlap=0.15, connect=True):
|
||||
"""
|
||||
Creates geometry inside a polygon for a tool to cover
|
||||
the whole area.
|
||||
|
@ -622,6 +623,7 @@ class Geometry(object):
|
|||
# geoms = Geometry.path_connect(geoms)
|
||||
|
||||
# Optimization: Reduce lifts
|
||||
if connect:
|
||||
log.debug("Reducing tool lifts...")
|
||||
geoms = Geometry.paint_connect(geoms, polygon, tooldia)
|
||||
|
||||
|
|
Loading…
Reference in New Issue