From d13b4ef14f989cf03d02ffdffc0a80936d8bcc64 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Tue, 15 Feb 2022 04:22:36 +0200 Subject: [PATCH] - in Tcl command `add_polygon` added ability to use `-p_coords` optional parameter where the value of this argument should be a list of tuple coordinates --- CHANGELOG.md | 1 + app_Main.py | 3 ++- defaults.py | 3 ++- tclCommands/TclCommandAddPolygon.py | 26 +++++++++++++++++++------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5828111..d71dbab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG for FlatCAM beta - fixed an issue with the moving shape when creating an exclusion area - added ability to copy the coordinates of the exclusion area with the context menu actions in the Exclusion areas table found in the Milling/Drilling plugins +- in Tcl command `add_polygon` added ability to use `-p_coords` optional parameter where the value of this argument should be a list of tuple coordinates 13.02.2022 diff --git a/app_Main.py b/app_Main.py index 5f53b39a..9103bf13 100644 --- a/app_Main.py +++ b/app_Main.py @@ -667,7 +667,8 @@ class App(QtCore.QObject): 'has_offset', 'holes', 'hpgl', 'iso_type', 'join', 'keep_scripts', 'las_min_pwr', 'las_power', 'margin', 'marlin', 'method', 'milled_dias', 'minoffset', 'min_bounds', 'name', 'offset', 'opt_type', 'order', - 'outname', 'overlap', 'obj_name', 'passes', 'postamble', 'pp', 'ppname_e', 'ppname_g', + 'outname', 'overlap', 'obj_name', + 'p_coords', 'passes', 'postamble', 'pp', 'ppname_e', 'ppname_g', 'preamble', 'radius', 'ref', 'rest', 'rows', 'shellvar_', 'scale_factor', 'spacing_columns', 'spacing_rows', 'spindlespeed', 'startz', 'startxy', diff --git a/defaults.py b/defaults.py index bbb6093a..3d72a211 100644 --- a/defaults.py +++ b/defaults.py @@ -811,7 +811,8 @@ class FlatCAMDefaults: 'las_min_pwr, las_power, keep_scripts, margin, marlin, method, milled_dias, ' 'minoffset, min_bounds, name, offset, opt_type, order, ' 'outname, overlap, obj_name, ' - 'passes, postamble, pp, ppname_e, ppname_g, preamble, radius, ref, rest, ' + 'p_coords, passes, postamble, pp, ppname_e, ppname_g, preamble, radius, ref, ' + 'rest, ' 'rows, shellvar_, scale_factor, spacing_columns, spacing_rows, spindlespeed, ' 'startz, startxy, toolchange_xy, toolchangez, ' 'tooldia, travelz, use_threads, value, ' diff --git a/tclCommands/TclCommandAddPolygon.py b/tclCommands/TclCommandAddPolygon.py index 4e879398..411cc65a 100644 --- a/tclCommands/TclCommandAddPolygon.py +++ b/tclCommands/TclCommandAddPolygon.py @@ -17,7 +17,9 @@ class TclCommandAddPolygon(TclCommandSignaled): ]) # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value - option_types = collections.OrderedDict() + option_types = collections.OrderedDict([ + ('p_coords', str) + ]) # array of mandatory options for current Tcl command: required = {'name','outname'} required = ['name'] @@ -27,10 +29,13 @@ class TclCommandAddPolygon(TclCommandSignaled): 'main': "Creates a polygon in the given Geometry object.", 'args': collections.OrderedDict([ ('name', 'Name of the Geometry object to which to append the polygon.'), + ('p_coords', 'Optional. If used it needs to be a list of tuple point coords (x,y). ' + 'Brackets: "[" or "]" are not allowed. If spaces are used then enclose with quotes.'), ('xi, yi', 'Coordinates of points in the polygon.') ]), 'examples': [ - 'add_polygon [x3 y3 [...]]' + 'add_polygon [x3 y3 [...]]', + 'add_poly -p_coords "(5.0, 5.0), (6.0, 5.0), (6.0, 6.0), (5.0, 6.0), (5.0, 5.0)"' ] } @@ -45,7 +50,6 @@ class TclCommandAddPolygon(TclCommandSignaled): """ name = args['name'] - obj = self.app.collection.get_by_name(name) if obj is None: self.raise_tcl_error("Object not found: %s" % name) @@ -53,10 +57,18 @@ class TclCommandAddPolygon(TclCommandSignaled): if obj.kind != 'geometry': self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj))) - if len(unnamed_args) % 2 != 0: + if 'p_coords' in args: + try: + points = list(eval(args['p_coords'])) + except Exception as err: + self.app.log.error("TclCommandAddPolygon.execute() -> %s" % str(err)) + return + + obj.add_polygon(points) + elif len(unnamed_args) % 2 != 0: self.raise_tcl_error("Incomplete coordinates.") - nr_points = int(len(unnamed_args) / 2) - points = [[float(unnamed_args[2*i]), float(unnamed_args[2*i+1])] for i in range(nr_points)] + nr_points = int(len(unnamed_args) / 2) + points = [[float(unnamed_args[2*i]), float(unnamed_args[2*i+1])] for i in range(nr_points)] - obj.add_polygon(points) + obj.add_polygon(points)