From b0ccc15f7015c432949d2b348f0e264c249ea41c Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 27 Nov 2020 15:16:17 +0200 Subject: [PATCH] - in Geometry Object Properties UI - finished the new feature Simplification and Vertex Points calculation which should greatly reduce the resulting GCode size --- CHANGELOG.md | 1 + appEditors/AppGeoEditor.py | 2 +- appObjects/FlatCAMGeometry.py | 62 +++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a24d282..32aaa601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ CHANGELOG for FlatCAM beta - fixed crash when launching with 2D Graphic Engine (due of recent changes) - in Geometry Editor - added new feature: Zoom on selected (by selecting a geometry element in the Geometry Table) - in Geometry Object Properties UI - added the UI for Utilities and within Utilities added the Simplification UI +- in Geometry Object Properties UI - finished the new feature Simplification and Vertex Points calculation which should greatly reduce the resulting GCode size 26.11.2020 diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index a78a7251..57097d4e 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -3951,7 +3951,7 @@ class AppGeoEditor(QtCore.QObject): selected_tree_items = self.tw.selectedItems() def task_job(): - with self.app.proc_container.new('%s...' % _("Working")): + with self.app.proc_container.new('%s...' % _("Simplify")): for sel in selected_tree_items: for obj_shape in self.storage.get_objects(): try: diff --git a/appObjects/FlatCAMGeometry.py b/appObjects/FlatCAMGeometry.py index 638eeef3..44100566 100644 --- a/appObjects/FlatCAMGeometry.py +++ b/appObjects/FlatCAMGeometry.py @@ -638,6 +638,12 @@ class GeometryObject(FlatCAMObj, Geometry): self.ui.geo_tools_table.setColumnHidden(2, True) self.ui.geo_tools_table.setColumnHidden(3, True) + # ############################################################################################################# + # ##################################### Setting Values######################################################### + # ############################################################################################################# + self.ui.vertex_points_entry.set_value(0) + self.ui.geo_tol_entry.set_value(10 ** -self.decimals) + # ############################################################################################################# # ################################ Signals Connection ######################################################### # ############################################################################################################# @@ -665,9 +671,8 @@ class GeometryObject(FlatCAMObj, Geometry): self.ui.milling_button.clicked.connect(self.on_milling_button_clicked) self.ui.util_button.clicked.connect(lambda st: self.ui.util_frame.show() if st else self.ui.util_frame.hide()) - - self.ui.vertex_points_entry.set_value(0) - self.ui.geo_tol_entry.set_value(10 ** -self.decimals) + self.ui.vertex_points_btn.clicked.connect(self.on_calculate_vertex_points) + self.ui.simplification_btn.clicked.connect(self.on_simplify_geometry) # # Postprocessor change # self.ui.pp_geometry_name_cb.activated.connect(self.on_pp_changed) @@ -715,6 +720,57 @@ class GeometryObject(FlatCAMObj, Geometry): current_obj = self.app.collection.get_active() self.app.milling_tool.ui.object_combo.set_value(current_obj.options['name']) + def on_calculate_vertex_points(self): + self.app.log.debug("GeometryObject.on_calculate_vertex_points()") + + vertex_points = 0 + + for tool in self.tools: + geometry = self.tools[tool]['solid_geometry'] + flattened_geo = self.flatten_list(obj_list=geometry) + for geo in flattened_geo: + if geo.geom_type == 'Polygon': + vertex_points += len(list(geo.exterior.coords)) + for int in geo.interiors: + vertex_points += len(list(int.coords)) + if geo.geom_type in ['LineString', 'LinearRing']: + vertex_points += len(list(geo.coords)) + + self.ui.vertex_points_entry.set_value(vertex_points) + self.app.inform.emit('[success] %s' % _("Vertex points calculated.")) + + def on_simplify_geometry(self): + self.app.log.debug("GeometryObject.on_simplify_geometry()") + + tol = self.ui.geo_tol_entry.get_value() + + def task_job(): + with self.app.proc_container.new('%s...' % _("Simplify")): + for tool in self.tools: + new_tool_geo = [] + geometry = self.tools[tool]['solid_geometry'] + flattened_geo = self.flatten_list(obj_list=geometry) + for geo in flattened_geo: + new_tool_geo.append(geo.simplify(tolerance=tol)) + self.tools[tool]['solid_geometry'] = deepcopy(new_tool_geo) + + # update the solid_geometry + total_geo = [] + for tool in self.tools: + total_geo += self.tools[tool]['solid_geometry'] + + self.solid_geometry = unary_union(total_geo) + + # plot the new geometry + self.app.plot_all() + + # update the vertex points number + self.on_calculate_vertex_points() + + self.app.inform.emit('[success] %s' % _("Done.")) + + self.app.worker_task.emit({'fcn': task_job, 'params': []}) + def on_rebuild_ui(self): # read the table tools uid current_uid_list = []