- added a new Tcl Command named SetPath which will set a path to be used by the Tcl commands. Once set will serve as a fallback path in case that the files fail to be opened first time. It will be persistent, saved in preferences. - added the GUI for the new Open Example in the FIle -> Scripting menu. - I am modifying all the open ... handlers to add a parameter that will flag if the method was launched from Tcl Shell. This way if the method will fail to open the filename (which include the path) it will try to open from a set fallback path. - fixed issue #406, bug introduced recently (leftover changes). - modified the ImportSVG Tcl command name to OpenSVG (open_svg alias) - added a new Tcl command named OpenDXF (open_dxf alias) - fixed some errors in Scripting features - added a new Tcl command named GetPath as a convenient way to get the current default path stored in App.defaults['global_tcl_path']
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
from tclCommands.TclCommand import TclCommand
|
|
import collections
|
|
import logging
|
|
|
|
import gettext
|
|
import FlatCAMTranslation as fcTranslate
|
|
import builtins
|
|
|
|
fcTranslate.apply_language('strings')
|
|
if '_' not in builtins.__dict__:
|
|
_ = gettext.gettext
|
|
|
|
log = logging.getLogger('base')
|
|
|
|
|
|
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']
|
|
|
|
description = '%s %s' % ("--", "Return in the console a list of bounds values for a list of objects.")
|
|
|
|
# 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] corresponding to each of the provided objects.",
|
|
'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 = []
|
|
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 = []
|
|
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
|