TclCommandOffset.py 1.4 KB

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