TclCommandDrillcncjob.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ('endz', 'Z distance at job end (example: 30.0).'),
  44. ('ppname_e', 'This is the Excellon postprocessor name: case_sensitive, no_quotes'),
  45. ('outname', 'Name of the resulting Geometry object.'),
  46. ('opt_type', 'Name of move optimization type. R by default from Rtree or '
  47. 'T from Travelling Salesman Algorithm')
  48. ]),
  49. 'examples': ['drillcncjob test.TXT -drillz -1.5 -travelz 14 -feedrate 222 -feedrate_rapid 456 -spindlespeed 777'
  50. ' -toolchange True -toolchangez 33 -endz 22 -ppname_e default\n'
  51. 'Usage of -feedrate_rapid matter only when the posptocessor is using it, like -marlin-.']
  52. }
  53. def execute(self, args, unnamed_args):
  54. """
  55. execute current TCL shell command
  56. :param args: array of known named arguments and options
  57. :param unnamed_args: array of other values which were passed into command
  58. without -somename and we do not have them in known arg_names
  59. :return: None or exception
  60. """
  61. name = args['name']
  62. if 'outname' not in args:
  63. args['outname'] = name + "_cnc"
  64. obj = self.app.collection.get_by_name(name)
  65. if obj is None:
  66. self.raise_tcl_error("Object not found: %s" % name)
  67. if not isinstance(obj, FlatCAMExcellon):
  68. self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj)))
  69. def job_init(job_obj, app_obj):
  70. drillz = args["drillz"] if "drillz" in args else obj.options["drillz"]
  71. job_obj.z_move = args["travelz"] if "travelz" in args else obj.options["travelz"]
  72. job_obj.feedrate = args["feedrate"] if "feedrate" in args else obj.options["feedrate"]
  73. job_obj.feedrate_rapid = args["feedrate_rapid"] if "feedrate_rapid" in args else obj.options["feedrate_rapid"]
  74. job_obj.spindlespeed = args["spindlespeed"] if "spindlespeed" in args else None
  75. job_obj.pp_excellon_name = args["ppname_e"] if "ppname_e" in args \
  76. else obj.options["ppname_e"]
  77. toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
  78. toolchangez = args["toolchangez"] if "toolchangez" in args else obj.options["toolchangez"]
  79. endz = args["endz"] if "endz" in args else obj.options["endz"]
  80. tools = args["tools"] if "tools" in args else 'all'
  81. opt_type = args["opt_type"] if "opt_type" in args else 'B'
  82. job_obj.generate_from_excellon_by_tool(obj, tools, drillz=drillz, toolchangez=toolchangez, endz=endz,
  83. toolchange=toolchange, excellon_optimization_type=opt_type)
  84. job_obj.gcode_parse()
  85. job_obj.create_geometry()
  86. self.app.new_object("cncjob", args['outname'], job_init)