From 6fae5258db4abacf8c5415e89285be1f5609a2c9 Mon Sep 17 00:00:00 2001 From: jpcaram Date: Fri, 26 Dec 2014 15:38:51 -0500 Subject: [PATCH] Subtract polygon. Cut path functional in Drawing tool. --- FlatCAMDraw.py | 45 +++++++++++++++++++++++++++++++++------- doc/source/planning.rst | 1 + share/cutpath16.png | Bin 0 -> 454 bytes share/cutpath24.png | Bin 0 -> 523 bytes share/cutpath32.png | Bin 0 -> 581 bytes 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 share/cutpath16.png create mode 100644 share/cutpath24.png create mode 100644 share/cutpath32.png diff --git a/FlatCAMDraw.py b/FlatCAMDraw.py index 67987a01..61d7c7af 100644 --- a/FlatCAMDraw.py +++ b/FlatCAMDraw.py @@ -506,6 +506,7 @@ class FlatCAMDraw(QtCore.QObject): self.add_path_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/path32.png'), 'Add Path') self.union_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/union32.png'), 'Polygon Union') self.subtract_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/subtract32.png'), 'Polygon Subtraction') + self.cutpath_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/cutpath32.png'), 'Cut Path') self.move_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/move32.png'), 'Move Objects') self.copy_btn = self.drawing_toolbar.addAction(QtGui.QIcon('share/copy32.png'), 'Copy Objects') @@ -539,6 +540,7 @@ class FlatCAMDraw(QtCore.QObject): self.union_btn.triggered.connect(self.union) self.subtract_btn.triggered.connect(self.subtract) + self.cutpath_btn.triggered.connect(self.cutpath) ## Toolbar events and properties self.tools = { @@ -627,6 +629,24 @@ class FlatCAMDraw(QtCore.QObject): self.drawing_toolbar.setDisabled(True) self.snap_toolbar.setDisabled(True) # TODO: Combine and move into tool + def cutpath(self): + selected = self.get_selected() + tools = selected[1:] + toolgeo = cascaded_union([shp.geo for shp in tools]) + + target = selected[0] + if type(target.geo) == Polygon: + for ring in poly2rings(target.geo): + self.add_shape(DrawToolShape(ring.difference(toolgeo))) + self.delete_shape(target) + elif type(target.geo) == LineString or type(target.geo) == LinearRing: + self.add_shape(DrawToolShape(target.geo.difference(toolgeo))) + self.delete_shape(target) + else: + self.app.log.warning("Not implemented.") + + self.replot() + def toolbar_tool_toggle(self, key): self.options[key] = self.sender().isChecked() print "grid_snap", self.options["grid_snap"] @@ -780,7 +800,8 @@ class FlatCAMDraw(QtCore.QObject): self.shape_buffer.remove(shape) # Add the new utility shape - self.shape_buffer.append(geo) + #self.shape_buffer.append(geo) + self.add_shape(geo) # Efficient plotting for fast animation @@ -792,10 +813,11 @@ class FlatCAMDraw(QtCore.QObject): #self.replot() - elements = self.axes.plot(x, y, 'bo', animated=True) - for el in elements: - self.axes.draw_artist(el) - self.canvas.canvas.blit(self.axes.bbox) + elements = self.axes.plot(x, y, 'bo', animated=True) + for el in elements: + self.axes.draw_artist(el) + + self.canvas.canvas.blit(self.axes.bbox) def on_canvas_key(self, event): """ @@ -961,9 +983,12 @@ class FlatCAMDraw(QtCore.QObject): assert shape.geo is not None assert (isinstance(shape.geo, list) and len(shape.geo) > 0) or not isinstance(shape.geo, list) - self.main_index.append(shape) self.shape_buffer.append(shape) - self.add2index(len(self.main_index) - 1, shape) + + # Do not add utility shapes to the index. + if not isinstance(shape, DrawToolUtilityShape): + self.main_index.append(shape) + self.add2index(len(self.main_index) - 1, shape) def plot_all(self): self.app.log.debug("plot_all()") @@ -1190,4 +1215,8 @@ def distance(pt1, pt2): def mag(vec): - return sqrt(vec[0] ** 2 + vec[1] ** 2) \ No newline at end of file + return sqrt(vec[0] ** 2 + vec[1] ** 2) + + +def poly2rings(poly): + return [poly.exterior] + [interior for interior in poly.interiors] \ No newline at end of file diff --git a/doc/source/planning.rst b/doc/source/planning.rst index 8cfe675c..d69a194f 100644 --- a/doc/source/planning.rst +++ b/doc/source/planning.rst @@ -13,6 +13,7 @@ Drawing * Group (But not union) * Remove from index (rebuild index or make deleted instances equal to None in the list). +* Better handling/abstraction of geometry types and lists of such. Algorithms diff --git a/share/cutpath16.png b/share/cutpath16.png new file mode 100644 index 0000000000000000000000000000000000000000..8693d35a31f4df5065081236518c09220be50b3c GIT binary patch literal 454 zcmV;%0XhDOP)GU$>;O+TrL;uF$_b3Ab17b7(fVd2|NH6fa|)qy(!LIfF3hsf9ZQCKhY&J8}s@vB-KuRf9zu&(qm&=Ssqhs<9e<7RAQYaL# zEbAyh>JT%T41>Xd;c$pj3g7qF#bR-37{*x?MPGjcs?{o$N(F$)WJ0Z0yKo%mvDs`s zo2L1(3)EV(*~W&Ha_xDZ{;BbJtN{(wxAEI|P{C@oVm_b8Y>UO>xEVxIB-`!wXG*M{ wWE9(D5<*-9Piz(`LCZ}G?}>o_>f~$u28)M^2sQvibpQYW07*qoM6N<$f=hb7xc~qF literal 0 HcmV?d00001 diff --git a/share/cutpath24.png b/share/cutpath24.png new file mode 100644 index 0000000000000000000000000000000000000000..1226f5c2e1b476a6b4198085fe1f835e68624297 GIT binary patch literal 523 zcmV+m0`&cfP)k8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H10fu;R7^* zAg{o{rcXgq1_mbwWF~PZabYWggc1_%aZs_KCG~IAlboSnzx#b(bMEaGRpmP?_O0qa zVPHiiw%hIf#bU9$jUys{tya5T!=lWf)oLB9>UG3Gr?zchJU>MG0#!W(tZKE2F(#DP z>-FxY)9FzVdu1RZhrn?VE0@bBl}d$7CWB>#XG$az{wB7@7Lg=y1MCFx!C*i-oyNB9 zQ1P(ZjFWm2*IX_qfn?bUM1N`u)BF&wUWo3HCq!n|hwdXfz64IGId7Zs7Yqj^p4s zP9%}7wK3#9z~^OnQF||J$kv9LDmYS=aS;3r6E^6!7gra*fRjQM7cYX?fKyAU&|@!b9bBs5Ruowci_vRI-Sn@X0yp| zw|hDOpad9RN%Q#}*L6by@R|V~Ktxm~llkl3M1*uYO)M6BQUCxnO`}*WlFerKw(WMy zbUF>C`B?w}UDwIwa{K4?dL1f2;IyhG=@*%tdoSgyJb(zg(zKYql9X`Nfv7psz`7U_z zw}MjYNWcT20_x#Z?L&FZz^BVz-+ literal 0 HcmV?d00001