TclCommandSkew.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  16. option_types = collections.OrderedDict([
  17. ('x', float),
  18. ('y', float)
  19. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['name']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Shear/Skew an object by angles along x and y dimensions. The reference point is the left corner of "
  25. "the bounding box of the object.",
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the object (Gerber, Geometry or Excellon) to be deformed (skewed). Required.'),
  28. ('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'),
  29. ('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')
  30. ]),
  31. 'examples': ['skew my_geometry -x 10.2 -y 3.5', 'skew my_geo -x 3.0']
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. :param args:
  36. :param unnamed_args:
  37. :return:
  38. """
  39. name = args['name']
  40. if 'x' in args:
  41. angle_x = float(args['x'])
  42. else:
  43. angle_x = 0.0
  44. if 'y' in args:
  45. angle_y = float(args['y'])
  46. else:
  47. angle_y = 0.0
  48. if angle_x == 0.0 and angle_y == 0.0:
  49. # nothing to be done
  50. return
  51. obj_to_skew = self.app.collection.get_by_name(name)
  52. xmin, ymin, xmax, ymax = obj_to_skew.bounds()
  53. obj_to_skew.skew(angle_x, angle_y, point=(xmin, ymin))