TclCommandAddRectangle.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from tclCommands.TclCommand import *
  2. class TclCommandAddRectangle(TclCommandSignaled):
  3. """
  4. Tcl shell command to add a rectange to the given Geometry object.
  5. """
  6. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  7. aliases = ['add_rectangle']
  8. # Dictionary of types from Tcl command, needs to be ordered.
  9. # For positional arguments
  10. arg_names = collections.OrderedDict([
  11. ('name', str),
  12. ('x0', float),
  13. ('y0', float),
  14. ('x1', float),
  15. ('y1', float)
  16. ])
  17. # Dictionary of types from Tcl command, needs to be ordered.
  18. # For options like -optionname value
  19. option_types = collections.OrderedDict([
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['name', 'x0', 'y0', 'x1', 'y1']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Add a rectange to the given Geometry object.",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the Geometry object in which to add the rectangle.'),
  28. ('x0 y0', 'Bottom left corner coordinates.'),
  29. ('x1 y1', 'Top right corner coordinates.')
  30. ]),
  31. 'examples': []
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. execute current TCL shell command
  36. :param args: array of known named arguments and options
  37. :param unnamed_args: array of other values which were passed into command
  38. without -somename and we do not have them in known arg_names
  39. :return: None or exception
  40. """
  41. obj_name = args['name']
  42. x0 = args['x0']
  43. y0 = args['y0']
  44. x1 = args['x1']
  45. y1 = args['y1']
  46. try:
  47. obj = self.app.collection.get_by_name(str(obj_name))
  48. except:
  49. return "Could not retrieve object: %s" % obj_name
  50. if obj is None:
  51. return "Object not found: %s" % obj_name
  52. obj.add_polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)])