TclCommandSkew.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from tclCommands.TclCommand import TclCommand
  2. import collections
  3. class TclCommandSkew(TclCommand):
  4. """
  5. Tcl shell command to skew the object by a an angle over X axis and an angle over Y axes.
  6. example:
  7. skew my_geometry 10.2 3.5
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['skew']
  11. description = '%s %s' % ("--", "Will deform (skew) the geometry of a named object. Does not create a new object.")
  12. # Dictionary of types from Tcl command, needs to be ordered
  13. arg_names = collections.OrderedDict([
  14. ('name', str),
  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. ('x', float),
  19. ('y', float)
  20. ])
  21. # array of mandatory options for current Tcl command: required = {'name','outname'}
  22. required = ['name']
  23. # structured help for current command, args needs to be ordered
  24. help = {
  25. 'main': "Shear/Skew an object along x and y dimensions. The reference point is the left corner of "
  26. "the bounding box of the object.",
  27. 'args': collections.OrderedDict([
  28. ('name', 'Name of the object (Gerber, Geometry or Excellon) to be deformed (skewed). Required.'),
  29. ('x', 'Angle in degrees by which to skew on the X axis. If it is not used it will be assumed to be 0.0'),
  30. ('y', 'Angle in degrees by which to skew on the Y axis. If it is not used it will be assumed to be 0.0')
  31. ]),
  32. 'examples': ['skew my_geometry -x 10.2 -y 3.5', 'skew my_geo -x 3.0']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. :param args:
  37. :param unnamed_args:
  38. :return:
  39. """
  40. name = args['name']
  41. if 'x' in args:
  42. angle_x = float(args['x'])
  43. else:
  44. angle_x = 0.0
  45. if 'y' in args:
  46. angle_y = float(args['y'])
  47. else:
  48. angle_y = 0.0
  49. if angle_x == 0.0 and angle_y == 0.0:
  50. # nothing to be done
  51. return
  52. obj_to_skew = self.app.collection.get_by_name(name)
  53. xmin, ymin, xmax, ymax = obj_to_skew.bounds()
  54. obj_to_skew.skew(angle_x, angle_y, point=(xmin, ymin))