- 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

@@ -78,8 +78,7 @@ class TclCommand(object):
:return: current command
"""
command_string = []
command_string = list()
command_string.append(self.aliases[0])
if self.original_args is not None:
@@ -117,7 +116,7 @@ class TclCommand(object):
if help_key in self.arg_names:
arg_type = self.arg_names[help_key]
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
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
self.app.worker_task.emit({'fcn': self.execute_call, 'params': [args, unnamed_args]})
return self.output
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'}
required = ['name']
required = []
# structured help for current command, args needs to be ordered
help = {
@@ -43,7 +43,9 @@ class TclCommandNewGeometry(TclCommandSignaled):
without -somename and we do not have them in known arg_names
:return: None or exception
"""
name = args['name']
if 'name' in args:
name = args['name']
else:
name = 'new_geo'
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 = filename.replace(' ', '')
args['plot'] = False
self.app.open_excellon(filename, **args)

View File

@@ -46,4 +46,7 @@ class TclCommandOpenGCode(TclCommandSignaled):
:return: None or exception
"""
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)))
# Opening the file happens here
self.app.progress.emit(30)
try:
gerber_obj.parse_file(filename)
except IOError:
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)
except ParseError as 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))
return
# Further parsing
app_obj.progress.emit(70)
filename = args['filename']
filename = filename.replace(' ', '')
if 'outname' in args:
outname = args['outname']
@@ -87,7 +81,5 @@ class TclCommandOpenGerber(TclCommandSignaled):
# Register recent file
self.app.file_opened.emit("gerber", filename)
self.app.progress.emit(100)
# GUI feedback
self.app.inform.emit("[success] Opened: " + filename)

View File

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

View File

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