TclCommandAddCircle.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from ObjectCollection import *
  2. import TclCommand
  3. class TclCommandAddCircle(TclCommand.TclCommand):
  4. """
  5. Tcl shell command to creates a circle in the given Geometry object.
  6. example:
  7. """
  8. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['add_circle']
  10. # Dictionary of types from Tcl command, needs to be ordered
  11. arg_names = collections.OrderedDict([
  12. ('name', str),
  13. ('center_x', float),
  14. ('center_y', float),
  15. ('radius', 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', 'center_x', 'center_y', 'radius']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Creates a circle in the given Geometry object.",
  25. 'args': collections.OrderedDict([
  26. ('name', 'Name of the geometry object to which to append the circle.'),
  27. ('center_x', 'X coordinate of the center of the circle.'),
  28. ('center_y', 'Y coordinates of the center of the circle.'),
  29. ('radius', 'Radius of the circle.')
  30. ]),
  31. 'examples': []
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. :param args:
  36. :param unnamed_args:
  37. :return:
  38. """
  39. obj_name = args['name']
  40. center_x = args['center_x']
  41. center_y = args['center_y']
  42. radius = args['radius']
  43. try:
  44. obj = self.app.collection.get_by_name(str(obj_name))
  45. except:
  46. return "Could not retrieve object: %s" % obj_name
  47. if obj is None:
  48. return "Object not found: %s" % obj_name
  49. obj.add_circle([float(center_x), float(center_y)], float(radius))