diff --git a/CHANGELOG.md b/CHANGELOG.md index a3907406..d515b916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ CHANGELOG for FlatCAM beta - All FCColorEntry GUI element instances have now a set icon for the title (and taskbar) - some changes to the FCMessageBox so the dark theme works ok on it +- fixed the Tcl Command 'set_origin' to work for a specified location +- updated the Tcl Command 'set_origin' to give the option to set the origin for a specified object 14.01.2022 diff --git a/app_Main.py b/app_Main.py index a230644b..7adde73b 100644 --- a/app_Main.py +++ b/app_Main.py @@ -5356,6 +5356,7 @@ class App(QtCore.QObject): app_obj.inform.emit('[success] %s...' % _('Origin set')) + # update the source_file container with the new offseted code for obj in obj_list: out_name = obj.options["name"] diff --git a/tclCommands/TclCommandSetOrigin.py b/tclCommands/TclCommandSetOrigin.py index 4656cce7..d721b3e2 100644 --- a/tclCommands/TclCommandSetOrigin.py +++ b/tclCommands/TclCommandSetOrigin.py @@ -43,7 +43,8 @@ class TclCommandSetOrigin(TclCommand): # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value option_types = collections.OrderedDict([ - ('auto', str) + ('auto', str), + ('obj_name', str) ]) # array of mandatory options for current Tcl command: required = {'name','outname'} @@ -57,9 +58,11 @@ class TclCommandSetOrigin(TclCommand): ('loc', 'Location to offset all the selected objects. NO SPACES ALLOWED in X and Y pair.\n' 'Use like this: 2,3'), ('auto', 'If set to True it will set the origin to the minimum x, y of the object selection bounding box.' - '-auto=True is not correct but -auto 1 or -auto True is correct. True (1) or False (0).') + '-auto=True is not correct but -auto 1 or -auto True is correct. True (1) or False (0).'), + ('obj_name', 'If used and followed by an object name that is already loaded, the origin for that object\n' + 'will be set at: "loc" - if used else the command will not be applied') ]), - 'examples': ['set_origin 3,2', 'set_origin -auto 1', 'origin'] + 'examples': ['set_origin 3,2', 'set_origin -auto 1', 'origin', 'set_origin 10,10 -obj_name "my_top_gerber"'] } def execute(self, args, unnamed_args): @@ -87,13 +90,29 @@ class TclCommandSetOrigin(TclCommand): log.debug("TclCommandSetOrigin.execute --> %s" % str(e)) location = (0, 0) - loc.append(location[0]) - loc.append(location[1]) - if len(location) != 2: self.raise_tcl_error('%s: %s' % ( _("Expected a pair of (x, y) coordinates. Got"), str(len(location)))) return 'fail' + + if 'obj_name' not in args: + objs = self.app.collection.get_list() + minx, miny, __, ___ = get_bounds(objs) + + loc.append(location[0] - minx) + loc.append(location[1] - miny) + else: + object_name = args['obj_name'] + obj = self.app.collection.get_by_name(object_name) + minx, miny, __, ___ = get_bounds([obj]) + + loc.append(location[0] - minx) + loc.append(location[1] - miny) + obj.offset((loc[0], loc[1])) + msg = '[success] Tcl %s %s %s: %s' % ( + _("Done."), _("Offsetting..."), object_name, '{0:.4f}, {0:.4f}'.format(loc[0], loc[1])) + self.app.inform_shell.emit(msg) + return else: loc = [0, 0]