TclCommandDrillcncjob.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. from ObjectCollection import *
  2. from tclCommands.TclCommand import TclCommandSignaled
  3. class TclCommandDrillcncjob(TclCommandSignaled):
  4. """
  5. Tcl shell command to Generates a Drill CNC Job from a Excellon Object.
  6. """
  7. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['drillcncjob']
  9. # dictionary of types from Tcl command, needs to be ordered
  10. arg_names = collections.OrderedDict([
  11. ('name', str)
  12. ])
  13. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  14. option_types = collections.OrderedDict([
  15. ('tools', str),
  16. ('drillz', float),
  17. ('travelz', float),
  18. ('feedrate', float),
  19. ('feedrate_rapid', float),
  20. ('spindlespeed', int),
  21. ('toolchange', bool),
  22. ('toolchangez', float),
  23. ('endz', float),
  24. ('ppname_e', str),
  25. ('outname', str),
  26. ('opt_type', str)
  27. ])
  28. # array of mandatory options for current Tcl command: required = {'name','outname'}
  29. required = ['name']
  30. # structured help for current command, args needs to be ordered
  31. help = {
  32. 'main': "Generates a Drill CNC Job from a Excellon Object.",
  33. 'args': collections.OrderedDict([
  34. ('name', 'Name of the source object.'),
  35. ('tools', 'Comma separated indexes of tools (example: 1,3 or 2) or select all if not specified.'),
  36. ('drillz', 'Drill depth into material (example: -2.0).'),
  37. ('travelz', 'Travel distance above material (example: 2.0).'),
  38. ('feedrate', 'Drilling feed rate.'),
  39. ('feedrate_rapid', 'Rapid drilling feed rate.'),
  40. ('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
  41. ('toolchange', 'Enable tool changes (example: True).'),
  42. ('toolchangez', 'Z distance for toolchange (example: 30.0).'),
  43. ('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
  44. ('endz', 'Z distance at job end (example: 30.0).'),
  45. ('ppname_e', 'This is the Excellon postprocessor name: case_sensitive, no_quotes'),
  46. ('outname', 'Name of the resulting Geometry object.'),
  47. ('opt_type', 'Name of move optimization type. R by default from Rtree or '
  48. 'T from Travelling Salesman Algorithm')
  49. ]),
  50. 'examples': ['drillcncjob test.TXT -drillz -1.5 -travelz 14 -feedrate 222 -feedrate_rapid 456 -spindlespeed 777'
  51. ' -toolchange True -toolchangez 33 -endz 22 -ppname_e default\n'
  52. 'Usage of -feedrate_rapid matter only when the posptocessor is using it, like -marlin-.']
  53. }
  54. def execute(self, args, unnamed_args):
  55. """
  56. execute current TCL shell command
  57. :param args: array of known named arguments and options
  58. :param unnamed_args: array of other values which were passed into command
  59. without -somename and we do not have them in known arg_names
  60. :return: None or exception
  61. """
  62. name = args['name']
  63. if 'outname' not in args:
  64. args['outname'] = name + "_cnc"
  65. obj = self.app.collection.get_by_name(name)
  66. if obj is None:
  67. self.raise_tcl_error("Object not found: %s" % name)
  68. if not isinstance(obj, FlatCAMExcellon):
  69. self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj)))
  70. xmin = obj.options['xmin']
  71. ymin = obj.options['ymin']
  72. xmax = obj.options['xmax']
  73. ymax = obj.options['ymax']
  74. def job_init(job_obj, app_obj):
  75. drillz = args["drillz"] if "drillz" in args else obj.options["drillz"]
  76. job_obj.z_move = args["travelz"] if "travelz" in args else obj.options["travelz"]
  77. job_obj.feedrate = args["feedrate"] if "feedrate" in args else obj.options["feedrate"]
  78. job_obj.feedrate_rapid = args["feedrate_rapid"] \
  79. if "feedrate_rapid" in args else obj.options["feedrate_rapid"]
  80. job_obj.spindlespeed = args["spindlespeed"] if "spindlespeed" in args else None
  81. job_obj.pp_excellon_name = args["ppname_e"] if "ppname_e" in args \
  82. else obj.options["ppname_e"]
  83. job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
  84. job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
  85. job_obj.options['type'] = 'Excellon'
  86. toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
  87. toolchangez = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
  88. job_obj.toolchangexy = args["toolchangexy"] if "toolchangexy" in args else obj.options["toolchangexy"]
  89. job_obj.toolchange_xy_type = "excellon"
  90. job_obj.options['xmin'] = xmin
  91. job_obj.options['ymin'] = ymin
  92. job_obj.options['xmax'] = xmax
  93. job_obj.options['ymax'] = ymax
  94. endz = args["endz"] if "endz" in args else obj.options["endz"]
  95. tools = args["tools"] if "tools" in args else 'all'
  96. opt_type = args["opt_type"] if "opt_type" in args else 'B'
  97. job_obj.generate_from_excellon_by_tool(obj, tools, drillz=drillz, toolchangez=toolchangez,
  98. endz=endz,
  99. toolchange=toolchange, excellon_optimization_type=opt_type)
  100. job_obj.gcode_parse()
  101. job_obj.create_geometry()
  102. self.app.new_object("cncjob", args['outname'], job_init)