TclCommandCncjob.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommandSignaled
  3. class TclCommandCncjob(TclCommandSignaled):
  4. """
  5. Tcl shell command to Generates a CNC Job from a Geometry Object.
  6. example:
  7. set_sys units MM
  8. new
  9. open_gerber tests/gerber_files/simple1.gbr -outname margin
  10. isolate margin -dia 3
  11. cncjob margin_iso
  12. """
  13. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  14. aliases = ['cncjob']
  15. # dictionary of types from Tcl command, needs to be ordered
  16. arg_names = collections.OrderedDict([
  17. ('name', str)
  18. ])
  19. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  20. option_types = collections.OrderedDict([
  21. ('z_cut', float),
  22. ('z_move', float),
  23. ('feedrate', float),
  24. ('feedrate_rapid', float),
  25. ('tooldia', float),
  26. ('spindlespeed', int),
  27. ('multidepth', bool),
  28. ('extracut', bool),
  29. ('depthperpass', float),
  30. ('endz', float),
  31. ('ppname_g', str),
  32. ('outname', str)
  33. ])
  34. # array of mandatory options for current Tcl command: required = {'name','outname'}
  35. required = ['name']
  36. # structured help for current command, args needs to be ordered
  37. help = {
  38. 'main': "Generates a CNC Job from a Geometry Object.",
  39. 'args': collections.OrderedDict([
  40. ('name', 'Name of the source object.'),
  41. ('tooldia', 'Tool diameter to show on screen.'),
  42. ('z_cut', 'Z-axis cutting position.'),
  43. ('z_move', 'Z-axis moving position.'),
  44. ('feedrate', 'Moving speed when cutting.'),
  45. ('feedrate_rapid', 'Rapid moving at speed when cutting.'),
  46. ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
  47. ('multidepth', 'Use or not multidepth cnccut. (True or False)'),
  48. ('depthperpass', 'Height of one layer for multidepth.'),
  49. ('extracut', 'Use or not an extra cnccut over the first point in path,in the job end (example: True)'),
  50. ('toolchange', 'Enable tool changes (example: True).'),
  51. ('toolchangez', 'Z distance for toolchange (example: 30.0).'),
  52. ('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
  53. ('endz', 'Height where the last move will park.'),
  54. ('outname', 'Name of the resulting Geometry object.'),
  55. ('ppname_g', 'Name of the Geometry postprocessor. No quotes, case sensitive')
  56. ]),
  57. 'examples': []
  58. }
  59. def execute(self, args, unnamed_args):
  60. """
  61. execute current TCL shell command
  62. :param args: array of known named arguments and options
  63. :param unnamed_args: array of other values which were passed into command
  64. without -somename and we do not have them in known arg_names
  65. :return: None or exception
  66. """
  67. name = args['name']
  68. if 'outname' not in args:
  69. args['outname'] = str(name) + "_cnc"
  70. obj = self.app.collection.get_by_name(str(name), isCaseSensitive=False)
  71. if obj is None:
  72. self.raise_tcl_error("Object not found: %s" % str(name))
  73. if not isinstance(obj, FlatCAMGeometry):
  74. self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (str(name), type(obj)))
  75. args["z_cut"] = args["z_cut"] if "z_cut" in args else obj.options["cutz"]
  76. args["z_move"] = args["z_move"] if "z_move" in args else obj.options["travelz"]
  77. args["feedrate"] = args["feedrate"] if "feedrate" in args else obj.options["feedrate"]
  78. args["feedrate_rapid"] = args["feedrate_rapid"] if "feedrate_rapid" in args else obj.options["feedrate_rapid"]
  79. args["spindlespeed"] = args["spindlespeed"] if "spindlespeed" in args else None
  80. args["tooldia"] = args["tooldia"] if "tooldia" in args else obj.options["cnctooldia"]
  81. args["multidepth"] = args["multidepth"] if "multidepth" in args else obj.options["multidepth"]
  82. args["depthperpass"] = args["depthperpass"] if "depthperpass" in args else obj.options["depthperpass"]
  83. args["extracut"] = args["extracut"] if "extracut" in args else obj.options["extracut"]
  84. args["endz"]= args["endz"] if "endz" in args else obj.options["endz"]
  85. args["ppname_g"] = args["ppname_g"] if "ppname_g" in args else obj.options["ppname_g"]
  86. args["toolchange"] = True if "toolchange" in args and args["toolchange"] == 1 else False
  87. args["toolchangez"] = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
  88. args["toolchangexy"] = args["toolchangexy"] if "toolchangexy" in args else obj.options["toolchangexy"]
  89. del args['name']
  90. # HACK !!! Should be solved elsewhere!!!
  91. # default option for multidepth is False
  92. obj.options['multidepth'] = False
  93. obj.generatecncjob(use_thread=False, **args)