TclCommandPaint.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from tclCommands.TclCommand import *
  2. class TclCommandPaint(TclCommandSignaled):
  3. """
  4. Paint the interior of polygons
  5. """
  6. # Array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  7. aliases = ['paint']
  8. # dictionary of types from Tcl command, needs to be ordered
  9. arg_names = collections.OrderedDict([
  10. ('name', str),
  11. ('tooldia', float),
  12. ('overlap', float)
  13. ])
  14. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  15. option_types = collections.OrderedDict([
  16. ('outname', str),
  17. ('all', bool),
  18. ('x', float),
  19. ('y', float)
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['name', 'tooldia', 'overlap']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Paint polygons",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the source Geometry object.'),
  28. ('tooldia', 'Diameter of the tool to be used.'),
  29. ('overlap', 'Fraction of the tool diameter to overlap cuts.'),
  30. ('outname', 'Name of the resulting Geometry object.'),
  31. ('all', 'Paint all polygons in the object.'),
  32. ('x', 'X value of coordinate for the selection of a single polygon.'),
  33. ('y', 'Y value of coordinate for the selection of a single polygon.')
  34. ]),
  35. 'examples': []
  36. }
  37. def execute(self, args, unnamed_args):
  38. """
  39. execute current TCL shell command
  40. :param args: array of known named arguments and options
  41. :param unnamed_args: array of other values which were passed into command
  42. without -somename and we do not have them in known arg_names
  43. :return: None or exception
  44. """
  45. name = args['name']
  46. tooldia = args['tooldia']
  47. overlap = args['overlap']
  48. if 'outname' in args:
  49. outname = args['outname']
  50. else:
  51. outname = name + "_paint"
  52. obj = self.app.collection.get_by_name(name)
  53. if obj is None:
  54. self.raise_tcl_error("Object not found: %s" % name)
  55. if not isinstance(obj, Geometry):
  56. self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
  57. if 'all' in args and args['all']:
  58. obj.paint_poly_all(tooldia, overlap, outname)
  59. return
  60. if 'x' not in args or 'y' not in args:
  61. self.raise_tcl_error('Expected -all 1 or -x <value> and -y <value>.')
  62. x = args['x']
  63. y = args['y']
  64. obj.paint_poly_single_click([x, y], tooldia, overlap, outname)