TclCommandAddCircle.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import collections
  2. from tclCommands.TclCommand import TclCommand
  3. class TclCommandAddCircle(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. description = '%s %s' % ("--", "Creates a circle in the given Geometry object.")
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ('center_x', float),
  15. ('center_y', float),
  16. ('radius', float)
  17. ])
  18. # Dictionary of types from Tcl command, needs to be ordered , this is 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', 'center_x', 'center_y', 'radius']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Creates a circle in the given Geometry object.",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the geometry object to which to append the circle.'),
  28. ('center_x', 'X coordinate of the center of the circle.'),
  29. ('center_y', 'Y coordinates of the center of the circle.'),
  30. ('radius', 'Radius of the circle.')
  31. ]),
  32. 'examples': ['add_circle geo_name 1.0 2.0 3']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. :param args:
  37. :param unnamed_args:
  38. :return:
  39. """
  40. name = args['name']
  41. center_x = args['center_x']
  42. center_y = args['center_y']
  43. radius = args['radius']
  44. try:
  45. obj = self.app.collection.get_by_name(str(name))
  46. except Exception:
  47. return "Could not retrieve object: %s" % name
  48. if obj is None:
  49. return "Object not found: %s" % name
  50. if obj.kind != 'geometry':
  51. self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
  52. obj.add_circle([float(center_x), float(center_y)], float(radius))