- added a new TclCommand named PlotObjects which will plot a list of FlatCAM objects

- made that after opening an object in FlatCAM it is not automatically plotted. If the user wants to plot it can use the TclCommands PlotAll or PlotObjects
- modified the TclCommands that open files to not plot the opened files automatically
This commit is contained in:
Marius Stanciu
2019-09-16 00:47:15 +03:00
committed by Marius
parent c06317374e
commit 2f553c9005
10 changed files with 122 additions and 51 deletions

View File

@@ -163,35 +163,36 @@ class TclCommand(object):
@staticmethod
def parse_arguments(args):
"""
Pre-processes arguments to detect '-keyword value' pairs into dictionary
and standalone parameters into list.
"""
Pre-processes arguments to detect '-keyword value' pairs into dictionary
and standalone parameters into list.
This is copy from FlatCAMApp.setup_shell().h() just for accessibility,
original should be removed after all commands will be converted
This is copy from FlatCAMApp.setup_shell().h() just for accessibility,
original should be removed after all commands will be converted
:param args: arguments from tcl to parse
:return: arguments, options
"""
:param args: arguments from tcl to parse
:return: arguments, options
"""
options = {}
arguments = []
n = len(args)
name = None
for i in range(n):
match = re.search(r'^-([a-zA-Z].*)', args[i])
if match:
assert name is None
name = match.group(1)
continue
options = {}
arguments = []
n = len(args)
if name is None:
arguments.append(args[i])
else:
options[name] = args[i]
name = None
name = None
for i in range(n):
match = re.search(r'^-([a-zA-Z].*)', args[i])
if match:
assert name is None
name = match.group(1)
continue
return arguments, options
if name is None:
arguments.append(args[i])
else:
options[name] = args[i]
name = None
return arguments, options
def check_args(self, args):
"""
@@ -274,7 +275,6 @@ class TclCommand(object):
"""
# self.worker_task.emit({'fcn': self.exec_command_test, 'params': [text, False]})
try:
self.log.debug("TCL command '%s' executed." % str(self.__class__))
self.original_args = args

View File

@@ -47,4 +47,5 @@ class TclCommandOpenExcellon(TclCommandSignaled):
filename = args.pop('filename')
args['plot'] = False
self.app.open_excellon(filename, **args)

View File

@@ -45,5 +45,5 @@ class TclCommandOpenGCode(TclCommandSignaled):
without -somename and we do not have them in known arg_names
:return: None or exception
"""
args['plot'] = False
self.app.open_gcode(args['filename'], **args)

View File

@@ -30,7 +30,7 @@ class TclCommandOpenGerber(TclCommandSignaled):
('filename', 'Path to file to open.'),
('outname', 'Name of the resulting Gerber object.')
]),
'examples': []
'examples': ["open_gerber gerber_object_path -outname bla"]
}
def execute(self, args, unnamed_args):
@@ -76,12 +76,13 @@ class TclCommandOpenGerber(TclCommandSignaled):
outname = filename.split('/')[-1].split('\\')[-1]
if 'follow' in args:
self.raise_tcl_error("The 'follow' parameter is obsolete. To create 'follow' geometry use the 'follow' parameter for the Tcl Command isolate()")
self.raise_tcl_error("The 'follow' parameter is obsolete. To create 'follow' geometry use the 'follow' "
"parameter for the Tcl Command isolate()")
with self.app.proc_container.new("Opening Gerber"):
# Object creation
self.app.new_object("gerber", outname, obj_init)
self.app.new_object("gerber", outname, obj_init, plot=False)
# Register recent file
self.app.file_opened.emit("gerber", filename)

View File

@@ -43,5 +43,5 @@ class TclCommandOpenProject(TclCommandSignaled):
without -somename and we do not have them in known arg_names
:return: None or exception
"""
self.app.open_project(args['filename'])
filename = args['filename']
self.app.open_project(filename, cli=True, plot=False)

View File

@@ -2,7 +2,7 @@ from ObjectCollection import *
from tclCommands.TclCommand import TclCommand
class TclCommandPlot(TclCommand):
class TclCommandPlotAll(TclCommand):
"""
Tcl shell command to update the plot on the user interface.
@@ -11,7 +11,7 @@ class TclCommandPlot(TclCommand):
"""
# List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['plot']
aliases = ['plot_all']
# Dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([

View File

@@ -0,0 +1,51 @@
from ObjectCollection import *
from tclCommands.TclCommand import TclCommand
class TclCommandPlotObjects(TclCommand):
"""
Tcl shell command to update the plot on the user interface.
example:
plot
"""
# List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['plot_objects']
# Dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([
('names', 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': "Plot a list of objects.",
'args': collections.OrderedDict([
('names', "UA list of object names to be plotted.")
]),
'examples': ["plot_objects"]
}
def execute(self, args, unnamed_args):
"""
:param args:
:param unnamed_args:
:return:
"""
names = [x.strip() for x in args['names'].split(",")]
objs = []
for name in names:
objs.append(self.app.collection.get_by_name(name))
for obj in objs:
obj.plot()

View File

@@ -44,7 +44,8 @@ import tclCommands.TclCommandOpenProject
import tclCommands.TclCommandOptions
import tclCommands.TclCommandPaint
import tclCommands.TclCommandPanelize
import tclCommands.TclCommandPlot
import tclCommands.TclCommandPlotAll
import tclCommands.TclCommandPlotObjects
import tclCommands.TclCommandSaveProject
import tclCommands.TclCommandSaveSys
import tclCommands.TclCommandScale