TclCommandAddCircle.py 1.9 KB

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