From 29457e98672e4f3693716928ef4a698af90925e2 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 1 Nov 2021 00:53:52 +0200 Subject: [PATCH] - Cutout Plugin - improved the functionality in Manual mode: depending on the state of the Shape parameter different types of cutout manual geometry is generated - fixed a bug in the Editors when trying to launch the Editor without an object selected --- CHANGELOG.md | 5 ++++ appPlugins/ToolCutOut.py | 51 +++++++++++++++++++++++++++------------- app_Main.py | 4 ++++ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e235d4f..cd57f3e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ CHANGELOG for FlatCAM beta ================================================= +1.11.2021 + +- Cutout Plugin - improved the functionality in Manual mode: depending on the state of the Shape parameter different types of cutout manual geometry is generated +- fixed a bug in the Editors when trying to launch the Editor without an object selected + 31.10.2021 - in Markers Plugin made sure that whenever new markers are added, the previous ones are first cleared so there is no accumulative action diff --git a/appPlugins/ToolCutOut.py b/appPlugins/ToolCutOut.py index 891b6eeb..5a6bd1b7 100644 --- a/appPlugins/ToolCutOut.py +++ b/appPlugins/ToolCutOut.py @@ -420,9 +420,11 @@ class CutOut(AppTool): def on_cutout_shape_changed(self, state): if state: self.ui.generate_cutout_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/rectangle32.png')) + self.ui.man_geo_creation_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/rectangle32.png')) self.ui.cutout_shape_cb.setText('%s' % _("Rectangular")) else: self.ui.generate_cutout_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/irregular32.png')) + self.ui.man_geo_creation_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/irregular32.png')) self.ui.cutout_shape_cb.setText('%s' % _("Any")) def on_tool_add(self, custom_dia=None): @@ -1667,6 +1669,7 @@ class CutOut(AppTool): def geo_init(geo_obj, app_obj): geo_union = unary_union(cutout_obj.solid_geometry) + shape_type = self.ui.cutout_shape_cb.get_value() # True means rectangular shape if convex_box: geo = geo_union.convex_hull @@ -1675,11 +1678,22 @@ class CutOut(AppTool): if isinstance(geo_union, Polygon) or \ (isinstance(geo_union, list) and len(geo_union) == 1) or \ (isinstance(geo_union, MultiPolygon) and len(geo_union.geoms) == 1): - geo_obj.solid_geometry = geo_union.buffer(margin + abs(dia / 2)).exterior + + buff_geo = geo_union.buffer(margin + abs(dia / 2)).exterior + if shape_type is False: + geo_obj.solid_geometry = buff_geo + else: + geo_obj.solid_geometry = buff_geo.envelope elif isinstance(geo_union, MultiPolygon): - x0, y0, x1, y1 = geo_union.bounds - geo = box(x0, y0, x1, y1) - geo_obj.solid_geometry = geo.buffer(margin + abs(dia / 2)) + + if shape_type is False: + buff_geo = geo_union.buffer(margin + abs(dia / 2)) + geo_obj.solid_geometry = buff_geo + else: + x0, y0, x1, y1 = geo_union.bounds + geo = box(x0, y0, x1, y1) + buff_geo = geo.buffer(margin + abs(dia / 2)) + geo_obj.solid_geometry = buff_geo else: app_obj.inform.emit('[ERROR_NOTCL] %s: %s' % ( _("Geometry not supported"), type(geo_union))) @@ -1687,18 +1701,22 @@ class CutOut(AppTool): else: geo = geo_union geo = geo.buffer(margin + abs(dia / 2)) - if isinstance(geo, Polygon): - geo_obj.solid_geometry = geo.exterior - elif isinstance(geo, MultiPolygon): - solid_geo = [] - for poly in geo: - solid_geo.append(poly.exterior) - geo_obj.solid_geometry = deepcopy(solid_geo) - - geo_obj.options['tools_mill_tooldia'] = str(dia) - geo_obj.options['cutz'] = self.ui.cutz_entry.get_value() - geo_obj.options['multidepth'] = self.ui.mpass_cb.get_value() - geo_obj.options['depthperpass'] = self.ui.maxdepth_entry.get_value() + if shape_type is False: + if isinstance(geo, Polygon): + geo_obj.solid_geometry = geo.exterior + elif isinstance(geo, MultiPolygon): + solid_geo = [] + for poly in geo: + solid_geo.append(poly.exterior) + geo_obj.solid_geometry = deepcopy(solid_geo) + else: + if isinstance(geo, Polygon): + geo_obj.solid_geometry = geo.envelope.exterior + elif isinstance(geo, MultiPolygon): + solid_geo = [] + for poly in geo: + solid_geo.append(poly.envelope.exterior) + geo_obj.solid_geometry = deepcopy(unary_union(solid_geo).exterior) geo_obj.multigeo = True @@ -1709,6 +1727,7 @@ class CutOut(AppTool): geo_obj.tools[1]['solid_geometry'] = geo_obj.solid_geometry geo_obj.tools[1]['data']['name'] = outname + geo_obj.tools[1]['data']['tools_mill_tooldia'] = str(dia) geo_obj.tools[1]['data']['tools_mill_cutz'] = self.ui.cutz_entry.get_value() geo_obj.tools[1]['data']['tools_mill_multidepth'] = self.ui.mpass_cb.get_value() geo_obj.tools[1]['data']['tools_mill_depthperpass'] = self.ui.maxdepth_entry.get_value() diff --git a/app_Main.py b/app_Main.py index 79c5f670..a9f5177f 100644 --- a/app_Main.py +++ b/app_Main.py @@ -2543,6 +2543,10 @@ class App(QtCore.QObject): self.defaults.report_usage("object2editor()") edited_object = self.collection.get_active() + if edited_object is None: + self.inform.emit('[ERROR_NOTCL] %s %s' % (_("The Editor could not start."), _("No object is selected."))) + return + edited_object.build_ui() self.ui.notebook.setCurrentWidget(self.ui.properties_tab)