From e79a53012a115ff45d5605909184db1a9bc1dd2d Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 27 Nov 2020 02:05:04 +0200 Subject: [PATCH] - in Geometry Editor - added a new feature: Simplification. It will greatly reduce the number of vertex points in a geometry element selected in the Geometry Table thus potentially greatly reducing the resulting GCode number of lines --- CHANGELOG.md | 1 + appEditors/AppGeoEditor.py | 73 +++++++++++++++++- .../resources/dark_resources/simplify32.png | Bin 0 -> 1006 bytes assets/resources/simplify32.png | Bin 0 -> 859 bytes 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 assets/resources/dark_resources/simplify32.png create mode 100644 assets/resources/simplify32.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 308a23b4..0f643277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta - in Geometry Editor - made sure that the edited Geometry do not contain Shapely Points and that when adding shapes, that the geometry of that shapes is valid and non empty and it is not a Shapely Point - in Geometry Editor - added new information's (length, coordinates and vertex points number) for the geometric element selected in the Geometry Table - in Geometry Editor - added more parameters displayed for the geometric elements selected in the Geometry Table: is_valid, is_empty, is_ccw, is_simple, is_ring +- in Geometry Editor - added a new feature: Simplification. It will greatly reduce the number of vertex points in a geometry element selected in the Geometry Table thus potentially greatly reducing the resulting GCode number of lines 26.11.2020 diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index 8853231e..baeda832 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -3392,12 +3392,17 @@ class AppGeoEditor(QtCore.QObject): self.geo_font.setBold(True) self.geo_parent = self.tw.invisibleRootItem() + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) + grid0.addWidget(separator_line, 3, 0, 1, 2) + # Parameters Title param_title = FCLabel('%s:' % _("Parameters")) param_title.setToolTip( _("Geometry parameters.") ) - grid0.addWidget(param_title, 4, 0) + grid0.addWidget(param_title, 4, 0, 1, 2) # Is Valid is_valid_lbl = FCLabel('%s:' % _("Is Valid")) @@ -3463,6 +3468,47 @@ class AppGeoEditor(QtCore.QObject): grid0.addWidget(vertex_lbl, 22, 0) grid0.addWidget(self.geo_vertex_entry, 22, 1) + separator_line = QtWidgets.QFrame() + separator_line.setFrameShape(QtWidgets.QFrame.HLine) + separator_line.setFrameShadow(QtWidgets.QFrame.Sunken) + grid0.addWidget(separator_line, 23, 0, 1, 2) + + # Simplification + simplif_lbl = FCLabel('%s:' % _("Simplification")) + simplif_lbl.setToolTip( + _("Simplify a geometry element by reducing its vertex points number.") + ) + grid0.addWidget(simplif_lbl, 24, 0, 1, 2) + + simplification_tol_lbl = FCLabel('%s:' % _("Tolerance")) + simplification_tol_lbl.setToolTip( + _("All points in the simplified object will be\n" + "within the tolerance distance of the original geometry.") + ) + self.geo_tol_entry = FCDoubleSpinner() + self.geo_tol_entry.set_precision(self.decimals) + self.geo_tol_entry.setSingleStep(0.001) + self.geo_tol_entry.setWrapping(True) + self.geo_tol_entry.set_range(-10000.0000, 10000.0000) + self.geo_tol_entry.set_value(10 ** -self.decimals) + + grid0.addWidget(simplification_tol_lbl, 26, 0) + grid0.addWidget(self.geo_tol_entry, 26, 1) + + self.simplification_btn = FCButton(_("Simplify")) + self.simplification_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/simplify32.png')) + self.simplification_btn.setToolTip( + _("Simplify a geometry element by reducing its vertex points number.") + ) + self.simplification_btn.setStyleSheet(""" + QPushButton + { + font-weight: bold; + } + """) + + grid0.addWidget(self.simplification_btn, 27, 0, 1, 2) + layout.addStretch() # Editor @@ -3618,6 +3664,8 @@ class AppGeoEditor(QtCore.QObject): self.transform_complete.connect(self.on_transform_complete) + self.simplification_btn.clicked.connect(self.on_simplification_click) + # Event signals disconnect id holders self.mp = None self.mm = None @@ -3817,6 +3865,29 @@ class AppGeoEditor(QtCore.QObject): self.replot() + def on_simplification_click(self): + selected_shapes = [] + selected_shapes_geos = [] + tol = self.geo_tol_entry.get_value() + + selected_tree_items = self.tw.selectedItems() + for sel in selected_tree_items: + for obj_shape in self.storage.get_objects(): + try: + if id(obj_shape) == int(sel.text(0)): + selected_shapes.append(obj_shape) + selected_shapes_geos.append(obj_shape.geo.simplify(tolerance=tol)) + except ValueError: + pass + + for shape in selected_shapes: + self.delete_shape(shape=shape) + + for geo in selected_shapes_geos: + self.add_shape(DrawToolShape(geo)) + + self.build_ui_sig.emit() + def activate(self): # adjust the status of the menu entries related to the editor self.app.ui.menueditedit.setDisabled(True) diff --git a/assets/resources/dark_resources/simplify32.png b/assets/resources/dark_resources/simplify32.png new file mode 100644 index 0000000000000000000000000000000000000000..b0c894d86d48f5c697c0809f58f136f905986603 GIT binary patch literal 1006 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{-GzZ+Rj;xUkjGiz z5n0T@z;^_M8K-LVNdpDhOFVsD*`IJriJNo&Jbq(0P}3ey7sn8f<5wqpXT*kzwEZuh zbi-@WGT)%i&Pk3gOZ>eSid}3B5%3gYR&83+DzLF-A6stLLjLGq3w|g(Ix%x{lZ2vE z!JU1_1gNks=8I& zT)Ts^51W5U+Mr@C!}s!c*S`b**sn8v=d?W2|4DkgVUM;EGi$l474tpGAM#(Kg-Sm~4-kXHv`RpQ^>FJric>&5v#0Y=8RJmno$gZoQL4 zWJ1^O^R=JJvSvr(?k$hz*LH3*JT^h}^4Z+)TU36^rtCa<@ylXQj=w$8fie4fC4Q@1 zGj@(&VlQpcZF&CQYX0-gImiDz`*E#0qGYpm$3^MA44rOzNj<;6{hntf;s94xT7@bN=|EXFJ36lD~XB z6MLYtt}p$<@z#pD|5VHQl;7T;tJQn!jrEW2%pU8- zNFAFwW5tv?%dO)MY4*HQImEQR)v;&cm*PoNs^&?4m%J*`p4|9yy5YURxXnu2C-X#p z?^5}xzvJa?L#aoOs!RU%Yh_F>t-JDbWzb3U#F*xbOFzH1ZTlFN*mApRXWGfD$>05- z+|g-~=O~SfkK+*F@o?-Fxijg>)tL+-DNWl$r`skU{mHm9G{`_JbXn874{KMQ+~fGq z!p;B6cNg#dkMrd&HlJlG7kYeYkK@E6a%bjWa5|IE+Ov7f((Lzgbxr<;Rl>X6Z>elw zr+;29pj&SG6VqivYlBv-Ka?vvla)#3WYN&PEETh{4m< K&t;ucLK6T1m$Z8T literal 0 HcmV?d00001 diff --git a/assets/resources/simplify32.png b/assets/resources/simplify32.png new file mode 100644 index 0000000000000000000000000000000000000000..8625a8db4463f8eac1603926019047038845c93d GIT binary patch literal 859 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE0wix1Z>k4UEa{HEjtmSN`?>!lvVtU&J%W50 z7^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{-GzZ+Rj;xUkjGiz z5n0T@z;^_M8K-LVNdpDhOFVsD*`IJriJNIT?ViyA)THU@;uzv_{OVQj4*x_6wh#Ab z6rMJn-WnY_L1p@q2@xEgdWst*xizJ(KiO7rUbS=5)VaMvS(j8)H%>Th(2^vjcHQkv zPsS6o8P}hwJbypu;HAx$&-c9lZ2SH@5Y@K-mvdeF#BEmgq;GO73or71%s=G5g~R{O z_ehTOxmSO_XPw5eoR{fn+pQ;k0r?N-vu*R7cU3Mc++cZSR%`QG-Q8#04_^qjm@x7E zI;R`+&1>4k68Wk)+l?(%&v7k{T={L@PbD4Jt#MBxu0^iBzU%+I2*ouYuSy1J#TYB3 zFH7`K+;GC!)N9J`9D|6JH`%RA&raB}(67+SBVSxbRlDJA1l-8R?U|e z_$G$jQ;P8~W7vF0^wpH5v#bJc%oDR%`11L0sk8emmY8QGPn3GN@lt%5!``kf2TZ@$ z{gisQ=R(T#JkQV5DzrkRCK;@{A%gG5En;fo>z40H_*b&bqIjEt>JO{`3ev<(cb3=H@x=ewh5 z$jwj5OsmALp