TclCommandOffset.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. description = '%s %s' % ("--", "Will offset the geometry of a named object. Does not create a new object.")
  12. # Dictionary of types from Tcl command, needs to be ordered
  13. arg_names = collections.OrderedDict([
  14. ('name', str),
  15. ('x', float),
  16. ('y', float)
  17. ])
  18. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  19. option_types = collections.OrderedDict([
  20. ('x', float),
  21. ('y', float)
  22. ])
  23. # array of mandatory options for current Tcl command: required = {'name','outname'}
  24. required = ['name']
  25. # structured help for current command, args needs to be ordered
  26. help = {
  27. 'main': "Changes the position of the object on X and/or Y axis.",
  28. 'args': collections.OrderedDict([
  29. ('name', 'Name of the object to offset. Required.'),
  30. ('x', 'Offset distance in the X axis. If it is not used it will be assumed to be 0.0'),
  31. ('y', 'Offset distance in the Y axis. If it is not used it will be assumed to be 0.0')
  32. ]),
  33. 'examples': ['offset my_geometry -x 1.2 -y -0.3', 'offset my_geometry -x 1.0']
  34. }
  35. def execute(self, args, unnamed_args):
  36. """
  37. :param args:
  38. :param unnamed_args:
  39. :return:
  40. """
  41. name = args['name']
  42. off_x = args['x'] if 'x' in args else 0.0
  43. off_y = args['y'] if 'y' in args else 0.0
  44. x, y = float(off_x), float(off_y)
  45. if (x, y) == (0.0, 0.0):
  46. return
  47. self.app.collection.get_by_name(name).offset((x, y))