- added a new TclCommand named "bounds" which will return a list of bounds values from a supplied list of objects names. For use in Tcl Scripts.

This commit is contained in:
Marius Stanciu
2019-09-23 04:07:24 +03:00
committed by Marius
parent edbb690d1b
commit 27b7a7dce6
5 changed files with 86 additions and 3 deletions

View File

@@ -14,7 +14,8 @@ CAD program, and create G-Code for Isolation routing.
- in legacy graphic engine, fixed bug that made the old object disappear when a new object was loaded
- in legacy graphic engine, fixed bug that crashed the app when creating a new project
- in legacy graphic engine, fixed a bug that when deleting an object all objects where deleted
- added a new TclCommand named set_origin which will set the origin for all loaded objects to zero if the -auto True argument is used and to a certain x,y location if the format is: set_origin 5,7
- added a new TclCommand named "set_origin" which will set the origin for all loaded objects to zero if the -auto True argument is used and to a certain x,y location if the format is: set_origin 5,7
- added a new TclCommand named "bounds" which will return a list of bounds values from a supplied list of objects names. For use in Tcl Scripts
22.09.2019

View File

@@ -0,0 +1,81 @@
from tclCommands.TclCommand import TclCommand
from ObjectCollection import *
from camlib import get_bounds
import gettext
import FlatCAMTranslation as fcTranslate
import builtins
fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
class TclCommandBounds(TclCommand):
"""
Tcl shell command to return the bounds values for a supplied list of objects (identified by their names).
example:
"""
# List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['get_bounds', 'bounds']
# Dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([
('objects', str)
])
# Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
option_types = collections.OrderedDict([
])
# array of mandatory options for current Tcl command: required = {'name','outname'}
required = []
# structured help for current command, args needs to be ordered
help = {
'main': "Will return a list of bounds values, each set of bound values is "
"a list itself: [xmin, ymin, xmax, ymax].",
'args': collections.OrderedDict([
('objects', 'A list of object names separated by comma without spaces.'),
]),
'examples': ['bounds a_obj.GTL,b_obj.DRL']
}
def execute(self, args, unnamed_args):
"""
:param args:
:param unnamed_args:
:return:
"""
obj_list = list()
if 'objects' in args:
try:
obj_list = [str(obj_name) for obj_name in str(args['objects']).split(",") if obj_name != '']
except AttributeError as e:
log.debug("TclCommandBounds.execute --> %s" % str(e))
if not obj_list:
self.raise_tcl_error('%s: %s:' % (
_("Expected a list of objects names separated by comma. Got"), str(args['objects'])))
return 'fail'
else:
self.raise_tcl_error('%s: %s:' % (
_("Expected a list of objects names separated by comma. Got"), str(args['objects'])))
return 'fail'
result_list = list()
for name in obj_list:
obj = self.app.collection.get_by_name(name)
xmin, ymin, xmax, ymax = obj.bounds()
result_list.append([xmin, ymin, xmax, ymax])
self.app.inform.emit('[success] %s ...' %
_('TclCommand Bounds done.'))
return result_list

View File

@@ -136,6 +136,7 @@ class TclCommandCopperClear(TclCommand):
tools = [float(eval(dia)) for dia in tooldia.split(",") if dia != '']
except AttributeError:
tools = [float(tooldia)]
# store here the default data for Geometry Data
default_data = {}
default_data.update({

View File

@@ -14,7 +14,7 @@ if '_' not in builtins.__dict__:
class TclCommandSetOrigin(TclCommand):
"""
Tcl shell command to clear the text in the Tcl Shell browser.
Tcl shell command to set the origin to zero or to a specified location for all loaded objects in FlatCAM.
example:
@@ -55,7 +55,6 @@ class TclCommandSetOrigin(TclCommand):
:return:
"""
print(args)
loc = list()
if 'auto' in args:
if args['auto'] == 1:

View File

@@ -10,6 +10,7 @@ import tclCommands.TclCommandAddRectangle
import tclCommands.TclCommandAlignDrill
import tclCommands.TclCommandAlignDrillGrid
import tclCommands.TclCommandBbox
import tclCommands.TclCommandBounds
import tclCommands.TclCommandClearShell
import tclCommands.TclCommandCncjob
import tclCommands.TclCommandCopperClear