- added new TclCommands: NewExcellon, NewGerber

- fixed the TclCommand open_project
This commit is contained in:
Marius Stanciu 2019-09-16 02:57:46 +03:00 committed by Marius
parent 8cba74647f
commit 7aebf1c60a
11 changed files with 156 additions and 23 deletions

View File

@ -9575,7 +9575,7 @@ class App(QtCore.QObject):
3) Calls on_file_new() 3) Calls on_file_new()
4) Updates options 4) Updates options
5) Calls new_object() with the object's from_dict() as init method. 5) Calls new_object() with the object's from_dict() as init method.
6) Calls plot_all() 6) Calls plot_all() if plot=True
:param filename: Name of the file from which to load. :param filename: Name of the file from which to load.
:type filename: str :type filename: str
@ -9586,6 +9586,8 @@ class App(QtCore.QObject):
""" """
App.log.debug("Opening project: " + filename) App.log.debug("Opening project: " + filename)
# for some reason, setting ui_title does not work when this method is called from Tcl Shell
# it's because the TclCommand is run in another thread (it inherit TclCommandSignaled)
if cli is None: if cli is None:
self.set_ui_title(name=_("Loading Project ... Please Wait ...")) self.set_ui_title(name=_("Loading Project ... Please Wait ..."))
@ -9610,7 +9612,6 @@ class App(QtCore.QObject):
with lzma.open(filename) as f: with lzma.open(filename) as f:
file_content = f.read().decode('utf-8') file_content = f.read().decode('utf-8')
d = json.loads(file_content, object_hook=dict2obj) d = json.loads(file_content, object_hook=dict2obj)
except Exception as e: except Exception as e:
App.log.error("Failed to open project file: %s with error: %s" % (filename, str(e))) App.log.error("Failed to open project file: %s with error: %s" % (filename, str(e)))
self.inform.emit('[ERROR_NOTCL] %s: %s' % self.inform.emit('[ERROR_NOTCL] %s: %s' %
@ -9619,15 +9620,21 @@ class App(QtCore.QObject):
# Clear the current project # Clear the current project
# # NOT THREAD SAFE # ## # # NOT THREAD SAFE # ##
if run_from_arg is True or cli is True: if run_from_arg is True:
pass pass
elif cli is True:
self.delete_selection_shape()
else: else:
self.on_file_new() self.on_file_new()
# Project options # Project options
self.options.update(d['options']) self.options.update(d['options'])
self.project_filename = filename self.project_filename = filename
self.set_screen_units(self.options["units"])
# for some reason, setting ui_title does not work when this method is called from Tcl Shell
# it's because the TclCommand is run in another thread (it inherit TclCommandSignaled)
if cli is None:
self.set_screen_units(self.options["units"])
# Re create objects # Re create objects
App.log.debug(" **************** Started PROEJCT loading... **************** ") App.log.debug(" **************** Started PROEJCT loading... **************** ")
@ -9639,6 +9646,8 @@ class App(QtCore.QObject):
App.log.debug("Recreating from opened project an %s object: %s" % App.log.debug("Recreating from opened project an %s object: %s" %
(obj['kind'].capitalize(), obj['options']['name'])) (obj['kind'].capitalize(), obj['options']['name']))
# for some reason, setting ui_title does not work when this method is called from Tcl Shell
# it's because the TclCommand is run in another thread (it inherit TclCommandSignaled)
if cli is None: if cli is None:
self.set_ui_title(name="{} {}: {}".format(_("Loading Project ... restoring"), self.set_ui_title(name="{} {}: {}".format(_("Loading Project ... restoring"),
obj['kind'].upper(), obj['kind'].upper(),
@ -9648,13 +9657,16 @@ class App(QtCore.QObject):
self.new_object(obj['kind'], obj['options']['name'], obj_init, active=False, fit=False, plot=plot) self.new_object(obj['kind'], obj['options']['name'], obj_init, active=False, fit=False, plot=plot)
# self.plot_all()
self.inform.emit('[success] %s: %s' % self.inform.emit('[success] %s: %s' %
(_("Project loaded from"), filename)) (_("Project loaded from"), filename))
self.should_we_save = False self.should_we_save = False
self.file_opened.emit("project", filename) self.file_opened.emit("project", filename)
self.set_ui_title(name=self.project_filename)
# for some reason, setting ui_title does not work when this method is called from Tcl Shell
# it's because the TclCommand is run in another thread (it inherit TclCommandSignaled)
if cli is None:
self.set_ui_title(name=self.project_filename)
App.log.debug(" **************** Finished PROJECT loading... **************** ") App.log.debug(" **************** Finished PROJECT loading... **************** ")

View File

@ -26,6 +26,8 @@ CAD program, and create G-Code for Isolation routing.
- modified the TclCommands so that open files do not plot the opened files automatically - modified the TclCommands so that open files do not plot the opened files automatically
- made all TclCommands not to be plotted automatically - made all TclCommands not to be plotted automatically
- made sure that all TclCommands are not threaded - made sure that all TclCommands are not threaded
- added new TclCommands: NewExcellon, NewGerber
- fixed the TclCommand open_project
14.09.2019 14.09.2019

View File

@ -78,8 +78,7 @@ class TclCommand(object):
:return: current command :return: current command
""" """
command_string = list()
command_string = []
command_string.append(self.aliases[0]) command_string.append(self.aliases[0])
if self.original_args is not None: if self.original_args is not None:
@ -117,7 +116,7 @@ class TclCommand(object):
if help_key in self.arg_names: if help_key in self.arg_names:
arg_type = self.arg_names[help_key] arg_type = self.arg_names[help_key]
type_name = str(arg_type.__name__) type_name = str(arg_type.__name__)
#in_command_name = help_key + "<" + type_name + ">" # in_command_name = help_key + "<" + type_name + ">"
in_command_name = help_key in_command_name = help_key
elif help_key in self.option_types: elif help_key in self.option_types:
@ -416,7 +415,6 @@ class TclCommandSignaled(TclCommand):
# when operation will be really long is good to set it higher then defqault 30s # when operation will be really long is good to set it higher then defqault 30s
self.app.worker_task.emit({'fcn': self.execute_call, 'params': [args, unnamed_args]}) self.app.worker_task.emit({'fcn': self.execute_call, 'params': [args, unnamed_args]})
return self.output return self.output
except Exception as unknown: except Exception as unknown:

View File

@ -0,0 +1,51 @@
from ObjectCollection import *
from tclCommands.TclCommand import TclCommandSignaled
class TclCommandNewExcellon(TclCommandSignaled):
"""
Tcl shell command to subtract polygon from the given Geometry object.
"""
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['new_excellon']
# Dictionary of types from Tcl command, needs to be ordered.
# For positional arguments
arg_names = collections.OrderedDict([
('name', str)
])
# Dictionary of types from Tcl command, needs to be ordered.
# 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': "Creates a new empty Excellon object.",
'args': collections.OrderedDict([
('name', 'New object name.'),
]),
'examples': []
}
def execute(self, args, unnamed_args):
"""
execute current TCL shell command
:param args: array of known named arguments and options
:param unnamed_args: array of other values which were passed into command
without -somename and we do not have them in known arg_names
:return: None or exception
"""
if 'name' in args:
name = args['name']
else:
name = 'new_exc'
self.app.new_object('excellon', name, lambda x, y: None, plot=False)

View File

@ -23,7 +23,7 @@ class TclCommandNewGeometry(TclCommandSignaled):
]) ])
# array of mandatory options for current Tcl command: required = {'name','outname'} # array of mandatory options for current Tcl command: required = {'name','outname'}
required = ['name'] required = []
# structured help for current command, args needs to be ordered # structured help for current command, args needs to be ordered
help = { help = {
@ -43,7 +43,9 @@ class TclCommandNewGeometry(TclCommandSignaled):
without -somename and we do not have them in known arg_names without -somename and we do not have them in known arg_names
:return: None or exception :return: None or exception
""" """
if 'name' in args:
name = args['name'] name = args['name']
else:
name = 'new_geo'
self.app.new_object('geometry', str(name), lambda x, y: None, plot=False) self.app.new_object('geometry', str(name), lambda x, y: None, plot=False)

View File

@ -0,0 +1,68 @@
from ObjectCollection import *
from tclCommands.TclCommand import TclCommandSignaled
class TclCommandNewGerber(TclCommandSignaled):
"""
Tcl shell command to subtract polygon from the given Geometry object.
"""
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['new_gerber']
# Dictionary of types from Tcl command, needs to be ordered.
# For positional arguments
arg_names = collections.OrderedDict([
('name', str)
])
# Dictionary of types from Tcl command, needs to be ordered.
# 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': "Creates a new empty Gerber object.",
'args': collections.OrderedDict([
('name', 'New object name.'),
]),
'examples': []
}
def execute(self, args, unnamed_args):
"""
execute current TCL shell command
:param args: array of known named arguments and options
:param unnamed_args: array of other values which were passed into command
without -somename and we do not have them in known arg_names
:return: None or exception
"""
if 'name' in args:
name = args['name']
else:
name = 'new_grb'
def initialize(grb_obj, self):
grb_obj.multitool = False
grb_obj.source_file = []
grb_obj.multigeo = False
grb_obj.follow = False
grb_obj.apertures = {}
grb_obj.solid_geometry = []
try:
grb_obj.options['xmin'] = 0
grb_obj.options['ymin'] = 0
grb_obj.options['xmax'] = 0
grb_obj.options['ymax'] = 0
except KeyError:
pass
self.app.new_object('gerber', name, initialize, plot=False)

View File

@ -46,6 +46,7 @@ class TclCommandOpenExcellon(TclCommandSignaled):
""" """
filename = args.pop('filename') filename = args.pop('filename')
filename = filename.replace(' ', '')
args['plot'] = False args['plot'] = False
self.app.open_excellon(filename, **args) self.app.open_excellon(filename, **args)

View File

@ -46,4 +46,7 @@ class TclCommandOpenGCode(TclCommandSignaled):
:return: None or exception :return: None or exception
""" """
args['plot'] = False args['plot'] = False
self.app.open_gcode(args['filename'], **args) filename = args["filename"]
filename = filename.replace(' ', '')
self.app.open_gcode(filename, **args)

View File

@ -50,25 +50,19 @@ class TclCommandOpenGerber(TclCommandSignaled):
self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (outname, type(gerber_obj))) self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (outname, type(gerber_obj)))
# Opening the file happens here # Opening the file happens here
self.app.progress.emit(30)
try: try:
gerber_obj.parse_file(filename) gerber_obj.parse_file(filename)
except IOError: except IOError:
app_obj.inform.emit("[ERROR_NOTCL] Failed to open file: %s " % filename) app_obj.inform.emit("[ERROR_NOTCL] Failed to open file: %s " % filename)
app_obj.progress.emit(0)
self.raise_tcl_error('Failed to open file: %s' % filename) self.raise_tcl_error('Failed to open file: %s' % filename)
except ParseError as e: except ParseError as e:
app_obj.inform.emit("[ERROR_NOTCL] Failed to parse file: %s, %s " % (filename, str(e))) app_obj.inform.emit("[ERROR_NOTCL] Failed to parse file: %s, %s " % (filename, str(e)))
app_obj.progress.emit(0)
self.log.error(str(e)) self.log.error(str(e))
return return
# Further parsing
app_obj.progress.emit(70)
filename = args['filename'] filename = args['filename']
filename = filename.replace(' ', '')
if 'outname' in args: if 'outname' in args:
outname = args['outname'] outname = args['outname']
@ -87,7 +81,5 @@ class TclCommandOpenGerber(TclCommandSignaled):
# Register recent file # Register recent file
self.app.file_opened.emit("gerber", filename) self.app.file_opened.emit("gerber", filename)
self.app.progress.emit(100)
# GUI feedback # GUI feedback
self.app.inform.emit("[success] Opened: " + filename) self.app.inform.emit("[success] Opened: " + filename)

View File

@ -44,4 +44,6 @@ class TclCommandOpenProject(TclCommandSignaled):
:return: None or exception :return: None or exception
""" """
filename = args['filename'] filename = args['filename']
filename = filename.replace(' ', '')
self.app.open_project(filename, cli=True, plot=False) self.app.open_project(filename, cli=True, plot=False)

View File

@ -35,7 +35,9 @@ import tclCommands.TclCommandMillSlots
import tclCommands.TclCommandMirror import tclCommands.TclCommandMirror
import tclCommands.TclCommandNew import tclCommands.TclCommandNew
import tclCommands.TclCommandNregions import tclCommands.TclCommandNregions
import tclCommands.TclCommandNewExcellon
import tclCommands.TclCommandNewGeometry import tclCommands.TclCommandNewGeometry
import tclCommands.TclCommandNewGerber
import tclCommands.TclCommandOffset import tclCommands.TclCommandOffset
import tclCommands.TclCommandOpenExcellon import tclCommands.TclCommandOpenExcellon
import tclCommands.TclCommandOpenGCode import tclCommands.TclCommandOpenGCode