TclCommandPlotObjects.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File Author: Marius Adrian Stanciu (c) #
  4. # Date: 8/17/2019 #
  5. # MIT Licence #
  6. # ##########################################################
  7. from tclCommands.TclCommand import TclCommand
  8. import collections
  9. class TclCommandPlotObjects(TclCommand):
  10. """
  11. Tcl shell command to update the plot on the user interface.
  12. example:
  13. plot
  14. """
  15. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  16. aliases = ['plot_objects']
  17. description = '%s %s' % ("--", "Plot a specified list of objects in appGUI.")
  18. # Dictionary of types from Tcl command, needs to be ordered
  19. arg_names = collections.OrderedDict([
  20. ('names', str)
  21. ])
  22. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  23. option_types = collections.OrderedDict([
  24. ('plot_status', str)
  25. ])
  26. # array of mandatory options for current Tcl command: required = {'name','outname'}
  27. required = ['names']
  28. # structured help for current command, args needs to be ordered
  29. help = {
  30. 'main': "Plot a specified list of objects in appGUI.",
  31. 'args': collections.OrderedDict([
  32. ('names', "A list of object names to be plotted separated by comma. Required.\n"
  33. "WARNING: no spaces are allowed. If unsure enclose the entire list with quotes."),
  34. ('plot_status', 'If to display or not the objects: True (1) or False (0).')
  35. ]),
  36. 'examples': ["plot_objects gerber_obj.GRB,excellon_obj.DRL"]
  37. }
  38. def execute(self, args, unnamed_args):
  39. """
  40. :param args:
  41. :param unnamed_args:
  42. :return:
  43. """
  44. if 'plot_status' in args:
  45. if args['plot_status'] is None:
  46. plot_status = True
  47. else:
  48. plot_status = bool(eval(args['plot_status']))
  49. else:
  50. plot_status = True
  51. if self.app.cmd_line_headless != 1:
  52. names = [x.strip() for x in args['names'].split(",") if x != '']
  53. objs = []
  54. for name in names:
  55. obj = self.app.collection.get_by_name(name)
  56. obj.options["plot"] = True if plot_status is True else False
  57. objs.append(obj)
  58. for obj in objs:
  59. obj.plot()