TclCommandOffset.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommand
  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. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['name', 'x', 'y']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Changes the position of the object.",
  25. 'args': collections.OrderedDict([
  26. ('name', 'Name of the object to offset.'),
  27. ('x', 'Offset distance in the X axis.'),
  28. ('y', 'Offset distance in the Y axis')
  29. ]),
  30. 'examples': ['offset my_geometry 1.2 -0.3']
  31. }
  32. def execute(self, args, unnamed_args):
  33. """
  34. :param args:
  35. :param unnamed_args:
  36. :return:
  37. """
  38. name = args['name']
  39. x, y = args['x'], args['y']
  40. self.app.collection.get_by_name(name).offset((x, y))