TclCommandOffset.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from tclCommands.TclCommand import TclCommand
  2. import collections
  3. class TclCommandOffset(TclCommand):
  4. """
  5. Tcl shell command to change the position of the object.
  6. example:
  7. offset my_geometry 1.2 -0.3
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['offset']
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ('x', float),
  15. ('y', float)
  16. ])
  17. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  18. option_types = collections.OrderedDict([
  19. ('x', float),
  20. ('y', float)
  21. ])
  22. # array of mandatory options for current Tcl command: required = {'name','outname'}
  23. required = ['name']
  24. # structured help for current command, args needs to be ordered
  25. help = {
  26. 'main': "Changes the position of the object on X and/or Y axis.",
  27. 'args': collections.OrderedDict([
  28. ('name', 'Name of the object to offset. Required.'),
  29. ('x', 'Offset distance in the X axis. If it is not used it will be assumed to be 0.0'),
  30. ('y', 'Offset distance in the Y axis. If it is not used it will be assumed to be 0.0')
  31. ]),
  32. 'examples': ['offset my_geometry -x 1.2 -y -0.3', 'offset my_geometry -x 1.0']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. :param args:
  37. :param unnamed_args:
  38. :return:
  39. """
  40. name = args['name']
  41. off_x = args['x'] if 'x' in args else 0.0
  42. off_y = args['y'] if 'y' in args else 0.0
  43. x, y = float(off_x), float(off_y)
  44. if (x, y) == (0.0, 0.0):
  45. return
  46. self.app.collection.get_by_name(name).offset((x, y))