From f6d990136555d0d90a6315c25d5aa6d3f7d7facb Mon Sep 17 00:00:00 2001 From: Juan Pablo Caram Date: Thu, 27 Oct 2016 17:34:41 -0400 Subject: [PATCH] Added "connect" option for painting polygons. --- FlatCAMGUI.py | 33 +++++++++++++++++++++++++++++++-- FlatCAMObj.py | 17 +++++++++++------ GUIElements.py | 2 ++ ObjectUI.py | 17 ++++++++++++++--- camlib.py | 14 ++++++++------ 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/FlatCAMGUI.py b/FlatCAMGUI.py index 17170bbe..d06b09ed 100644 --- a/FlatCAMGUI.py +++ b/FlatCAMGUI.py @@ -651,7 +651,9 @@ class GeometryOptionsGroupUI(OptionsGroupUI): ) self.layout.addWidget(self.plot_cb) + # ------------------------------ ## Create CNC Job + # ------------------------------ self.cncjob_label = QtGui.QLabel('Create CNC Job:') 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('Paint Area:') 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:
" + "Standard: Fixed step inwards.
" + "Seed-based: 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): diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 3746bf51..674b529d 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -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()) diff --git a/GUIElements.py b/GUIElements.py index 3d9ca186..c2b728d6 100644 --- a/GUIElements.py +++ b/GUIElements.py @@ -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) diff --git a/ObjectUI.py b/ObjectUI.py index 08214032..5d1e765c 100644 --- a/ObjectUI.py +++ b/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:
" "Standard: Fixed step inwards.
" @@ -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') diff --git a/camlib.py b/camlib.py index b6e69a29..7720c536 100644 --- a/camlib.py +++ b/camlib.py @@ -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 - log.debug("Reducing tool lifts...") - geoms = Geometry.paint_connect(geoms, polygon, tooldia) + 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,8 +623,9 @@ class Geometry(object): # geoms = Geometry.path_connect(geoms) # Optimization: Reduce lifts - log.debug("Reducing tool lifts...") - geoms = Geometry.paint_connect(geoms, polygon, tooldia) + if connect: + log.debug("Reducing tool lifts...") + geoms = Geometry.paint_connect(geoms, polygon, tooldia) return geoms