FlatCAMExcellon.py 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # Author: Juan Pablo Caram (c) #
  5. # Date: 2/5/2014 #
  6. # MIT Licence #
  7. # ##########################################################
  8. # ##########################################################
  9. # File modified by: Marius Stanciu #
  10. # ##########################################################
  11. from shapely.geometry import Point, LineString
  12. from copy import deepcopy
  13. from flatcamParsers.ParseExcellon import Excellon
  14. from flatcamObjects.FlatCAMObj import *
  15. import itertools
  16. import gettext
  17. import FlatCAMTranslation as fcTranslate
  18. import builtins
  19. fcTranslate.apply_language('strings')
  20. if '_' not in builtins.__dict__:
  21. _ = gettext.gettext
  22. class ExcellonObject(FlatCAMObj, Excellon):
  23. """
  24. Represents Excellon/Drill code.
  25. """
  26. ui_type = ExcellonObjectUI
  27. optionChanged = QtCore.pyqtSignal(str)
  28. def __init__(self, name):
  29. self.decimals = self.app.decimals
  30. self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
  31. Excellon.__init__(self, geo_steps_per_circle=self.circle_steps)
  32. FlatCAMObj.__init__(self, name)
  33. self.kind = "excellon"
  34. self.options.update({
  35. "plot": True,
  36. "solid": False,
  37. "operation": "drill",
  38. "milling_type": "drills",
  39. "milling_dia": 0.04,
  40. "cutz": -0.1,
  41. "multidepth": False,
  42. "depthperpass": 0.7,
  43. "travelz": 0.1,
  44. "feedrate": self.app.defaults["geometry_feedrate"],
  45. "feedrate_z": 5.0,
  46. "feedrate_rapid": 5.0,
  47. "tooldia": 0.1,
  48. "slot_tooldia": 0.1,
  49. "toolchange": False,
  50. "toolchangez": 1.0,
  51. "toolchangexy": "0.0, 0.0",
  52. "extracut": self.app.defaults["geometry_extracut"],
  53. "extracut_length": self.app.defaults["geometry_extracut_length"],
  54. "endz": 2.0,
  55. "endxy": '',
  56. "startz": None,
  57. "offset": 0.0,
  58. "spindlespeed": 0,
  59. "dwell": True,
  60. "dwelltime": 1000,
  61. "ppname_e": 'default',
  62. "ppname_g": self.app.defaults["geometry_ppname_g"],
  63. "z_pdepth": -0.02,
  64. "feedrate_probe": 3.0,
  65. "optimization_type": "B",
  66. })
  67. # TODO: Document this.
  68. self.tool_cbs = {}
  69. # dict that holds the object names and the option name
  70. # the key is the object name (defines in ObjectUI) for each UI element that is a parameter
  71. # particular for a tool and the value is the actual name of the option that the UI element is changing
  72. self.name2option = {}
  73. # default set of data to be added to each tool in self.tools as self.tools[tool]['data'] = self.default_data
  74. self.default_data = {}
  75. # fill in self.default_data values from self.options
  76. for opt_key, opt_val in self.app.options.items():
  77. if opt_key.find('excellon_') == 0:
  78. self.default_data[opt_key] = deepcopy(opt_val)
  79. for opt_key, opt_val in self.app.options.items():
  80. if opt_key.find('geometry_') == 0:
  81. self.default_data[opt_key] = deepcopy(opt_val)
  82. # variable to store the total amount of drills per job
  83. self.tot_drill_cnt = 0
  84. self.tool_row = 0
  85. # variable to store the total amount of slots per job
  86. self.tot_slot_cnt = 0
  87. self.tool_row_slots = 0
  88. # variable to store the distance travelled
  89. self.travel_distance = 0.0
  90. # store the source file here
  91. self.source_file = ""
  92. self.multigeo = False
  93. self.units_found = self.app.defaults['units']
  94. self.fill_color = self.app.defaults['excellon_plot_fill']
  95. self.outline_color = self.app.defaults['excellon_plot_line']
  96. self.alpha_level = 'bf'
  97. # Attributes to be included in serialization
  98. # Always append to it because it carries contents
  99. # from predecessors.
  100. self.ser_attrs += ['options', 'kind']
  101. @staticmethod
  102. def merge(exc_list, exc_final, decimals=None):
  103. """
  104. Merge Excellon objects found in exc_list parameter into exc_final object.
  105. Options are always copied from source .
  106. Tools are disregarded, what is taken in consideration is the unique drill diameters found as values in the
  107. exc_list tools dict's. In the reconstruction section for each unique tool diameter it will be created a
  108. tool_name to be used in the final Excellon object, exc_final.
  109. If only one object is in exc_list parameter then this function will copy that object in the exc_final
  110. :param exc_list: List or one object of ExcellonObject Objects to join.
  111. :param exc_final: Destination ExcellonObject object.
  112. :return: None
  113. """
  114. if decimals is None:
  115. decimals = 4
  116. decimals_exc = decimals
  117. # flag to signal that we need to reorder the tools dictionary and drills and slots lists
  118. flag_order = False
  119. try:
  120. flattened_list = list(itertools.chain(*exc_list))
  121. except TypeError:
  122. flattened_list = exc_list
  123. # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
  124. # values will be list of Shapely Points; for drills
  125. custom_dict_drills = {}
  126. # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
  127. # values will be list of Shapely Points; for slots
  128. custom_dict_slots = {}
  129. for exc in flattened_list:
  130. # copy options of the current excellon obj to the final excellon obj
  131. for option in exc.options:
  132. if option != 'name':
  133. try:
  134. exc_final.options[option] = exc.options[option]
  135. except Exception:
  136. exc.app.log.warning("Failed to copy option.", option)
  137. for drill in exc.drills:
  138. exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[drill['tool']]['C']))
  139. if exc_tool_dia not in custom_dict_drills:
  140. custom_dict_drills[exc_tool_dia] = [drill['point']]
  141. else:
  142. custom_dict_drills[exc_tool_dia].append(drill['point'])
  143. for slot in exc.slots:
  144. exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[slot['tool']]['C']))
  145. if exc_tool_dia not in custom_dict_slots:
  146. custom_dict_slots[exc_tool_dia] = [[slot['start'], slot['stop']]]
  147. else:
  148. custom_dict_slots[exc_tool_dia].append([slot['start'], slot['stop']])
  149. # add the zeros and units to the exc_final object
  150. exc_final.zeros = exc.zeros
  151. exc_final.units = exc.units
  152. # ##########################################
  153. # Here we add data to the exc_final object #
  154. # ##########################################
  155. # variable to make tool_name for the tools
  156. current_tool = 0
  157. # The tools diameter are now the keys in the drill_dia dict and the values are the Shapely Points in case of
  158. # drills
  159. for tool_dia in custom_dict_drills:
  160. # we create a tool name for each key in the drill_dia dict (the key is a unique drill diameter)
  161. current_tool += 1
  162. tool_name = str(current_tool)
  163. spec = {"C": float(tool_dia)}
  164. exc_final.tools[tool_name] = spec
  165. # rebuild the drills list of dict's that belong to the exc_final object
  166. for point in custom_dict_drills[tool_dia]:
  167. exc_final.drills.append(
  168. {
  169. "point": point,
  170. "tool": str(current_tool)
  171. }
  172. )
  173. # The tools diameter are now the keys in the drill_dia dict and the values are a list ([start, stop])
  174. # of two Shapely Points in case of slots
  175. for tool_dia in custom_dict_slots:
  176. # we create a tool name for each key in the slot_dia dict (the key is a unique slot diameter)
  177. # but only if there are no drills
  178. if not exc_final.tools:
  179. current_tool += 1
  180. tool_name = str(current_tool)
  181. spec = {"C": float(tool_dia)}
  182. exc_final.tools[tool_name] = spec
  183. else:
  184. dia_list = []
  185. for v in exc_final.tools.values():
  186. dia_list.append(float(v["C"]))
  187. if tool_dia not in dia_list:
  188. flag_order = True
  189. current_tool = len(dia_list) + 1
  190. tool_name = str(current_tool)
  191. spec = {"C": float(tool_dia)}
  192. exc_final.tools[tool_name] = spec
  193. else:
  194. for k, v in exc_final.tools.items():
  195. if v["C"] == tool_dia:
  196. current_tool = int(k)
  197. break
  198. # rebuild the slots list of dict's that belong to the exc_final object
  199. for point in custom_dict_slots[tool_dia]:
  200. exc_final.slots.append(
  201. {
  202. "start": point[0],
  203. "stop": point[1],
  204. "tool": str(current_tool)
  205. }
  206. )
  207. # flag_order == True means that there was an slot diameter not in the tools and we also have drills
  208. # and the new tool was added to self.tools therefore we need to reorder the tools and drills and slots
  209. current_tool = 0
  210. if flag_order is True:
  211. dia_list = []
  212. temp_drills = []
  213. temp_slots = []
  214. temp_tools = {}
  215. for v in exc_final.tools.values():
  216. dia_list.append(float(v["C"]))
  217. dia_list.sort()
  218. for ordered_dia in dia_list:
  219. current_tool += 1
  220. tool_name_temp = str(current_tool)
  221. spec_temp = {"C": float(ordered_dia)}
  222. temp_tools[tool_name_temp] = spec_temp
  223. for drill in exc_final.drills:
  224. exc_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[drill['tool']]['C']))
  225. if exc_tool_dia == ordered_dia:
  226. temp_drills.append(
  227. {
  228. "point": drill["point"],
  229. "tool": str(current_tool)
  230. }
  231. )
  232. for slot in exc_final.slots:
  233. slot_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[slot['tool']]['C']))
  234. if slot_tool_dia == ordered_dia:
  235. temp_slots.append(
  236. {
  237. "start": slot["start"],
  238. "stop": slot["stop"],
  239. "tool": str(current_tool)
  240. }
  241. )
  242. # delete the exc_final tools, drills and slots
  243. exc_final.tools = {}
  244. exc_final.drills[:] = []
  245. exc_final.slots[:] = []
  246. # update the exc_final tools, drills and slots with the ordered values
  247. exc_final.tools = temp_tools
  248. exc_final.drills[:] = temp_drills
  249. exc_final.slots[:] = temp_slots
  250. # create the geometry for the exc_final object
  251. exc_final.create_geometry()
  252. def build_ui(self):
  253. FlatCAMObj.build_ui(self)
  254. self.units = self.app.defaults['units'].upper()
  255. for row in range(self.ui.tools_table.rowCount()):
  256. try:
  257. # if connected, disconnect the signal from the slot on item_changed as it creates issues
  258. offset_spin_widget = self.ui.tools_table.cellWidget(row, 4)
  259. offset_spin_widget.valueChanged.disconnect()
  260. except (TypeError, AttributeError):
  261. pass
  262. n = len(self.tools)
  263. # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
  264. self.ui.tools_table.setRowCount(n + 2)
  265. self.tot_drill_cnt = 0
  266. self.tot_slot_cnt = 0
  267. self.tool_row = 0
  268. sort = []
  269. for k, v in list(self.tools.items()):
  270. sort.append((k, v.get('C')))
  271. sorted_tools = sorted(sort, key=lambda t1: t1[1])
  272. tools = [i[0] for i in sorted_tools]
  273. new_options = {}
  274. for opt in self.options:
  275. new_options[opt] = self.options[opt]
  276. for tool_no in tools:
  277. # add the data dictionary for each tool with the default values
  278. self.tools[tool_no]['data'] = deepcopy(new_options)
  279. # self.tools[tool_no]['data']["tooldia"] = self.tools[tool_no]["C"]
  280. # self.tools[tool_no]['data']["slot_tooldia"] = self.tools[tool_no]["C"]
  281. drill_cnt = 0 # variable to store the nr of drills per tool
  282. slot_cnt = 0 # variable to store the nr of slots per tool
  283. # Find no of drills for the current tool
  284. for drill in self.drills:
  285. if drill['tool'] == tool_no:
  286. drill_cnt += 1
  287. self.tot_drill_cnt += drill_cnt
  288. # Find no of slots for the current tool
  289. for slot in self.slots:
  290. if slot['tool'] == tool_no:
  291. slot_cnt += 1
  292. self.tot_slot_cnt += slot_cnt
  293. exc_id_item = QtWidgets.QTableWidgetItem('%d' % int(tool_no))
  294. exc_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  295. dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.tools[tool_no]['C']))
  296. dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
  297. drill_count_item = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
  298. drill_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
  299. # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
  300. slot_count_str = '%d' % slot_cnt if slot_cnt > 0 else ''
  301. slot_count_item = QtWidgets.QTableWidgetItem(slot_count_str)
  302. slot_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
  303. plot_item = FCCheckBox()
  304. plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
  305. if self.ui.plot_cb.isChecked():
  306. plot_item.setChecked(True)
  307. self.ui.tools_table.setItem(self.tool_row, 0, exc_id_item) # Tool name/id
  308. self.ui.tools_table.setItem(self.tool_row, 1, dia_item) # Diameter
  309. self.ui.tools_table.setItem(self.tool_row, 2, drill_count_item) # Number of drills per tool
  310. self.ui.tools_table.setItem(self.tool_row, 3, slot_count_item) # Number of drills per tool
  311. empty_plot_item = QtWidgets.QTableWidgetItem('')
  312. empty_plot_item.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  313. self.ui.tools_table.setItem(self.tool_row, 5, empty_plot_item)
  314. self.ui.tools_table.setCellWidget(self.tool_row, 5, plot_item)
  315. self.tool_row += 1
  316. # add a last row with the Total number of drills
  317. empty_1 = QtWidgets.QTableWidgetItem('')
  318. empty_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  319. empty_1_1 = QtWidgets.QTableWidgetItem('')
  320. empty_1_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  321. empty_1_2 = QtWidgets.QTableWidgetItem('')
  322. empty_1_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  323. empty_1_3 = QtWidgets.QTableWidgetItem('')
  324. empty_1_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  325. label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
  326. tot_drill_count = QtWidgets.QTableWidgetItem('%d' % self.tot_drill_cnt)
  327. label_tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
  328. tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
  329. self.ui.tools_table.setItem(self.tool_row, 0, empty_1)
  330. self.ui.tools_table.setItem(self.tool_row, 1, label_tot_drill_count)
  331. self.ui.tools_table.setItem(self.tool_row, 2, tot_drill_count) # Total number of drills
  332. self.ui.tools_table.setItem(self.tool_row, 3, empty_1_1)
  333. self.ui.tools_table.setItem(self.tool_row, 5, empty_1_3)
  334. font = QtGui.QFont()
  335. font.setBold(True)
  336. font.setWeight(75)
  337. for k in [1, 2]:
  338. self.ui.tools_table.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
  339. self.ui.tools_table.item(self.tool_row, k).setFont(font)
  340. self.tool_row += 1
  341. # add a last row with the Total number of slots
  342. empty_2 = QtWidgets.QTableWidgetItem('')
  343. empty_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  344. empty_2_1 = QtWidgets.QTableWidgetItem('')
  345. empty_2_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  346. empty_2_2 = QtWidgets.QTableWidgetItem('')
  347. empty_2_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  348. empty_2_3 = QtWidgets.QTableWidgetItem('')
  349. empty_2_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  350. label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
  351. tot_slot_count = QtWidgets.QTableWidgetItem('%d' % self.tot_slot_cnt)
  352. label_tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
  353. tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
  354. self.ui.tools_table.setItem(self.tool_row, 0, empty_2)
  355. self.ui.tools_table.setItem(self.tool_row, 1, label_tot_slot_count)
  356. self.ui.tools_table.setItem(self.tool_row, 2, empty_2_1)
  357. self.ui.tools_table.setItem(self.tool_row, 3, tot_slot_count) # Total number of slots
  358. self.ui.tools_table.setItem(self.tool_row, 5, empty_2_3)
  359. for kl in [1, 2, 3]:
  360. self.ui.tools_table.item(self.tool_row, kl).setFont(font)
  361. self.ui.tools_table.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
  362. # sort the tool diameter column
  363. # self.ui.tools_table.sortItems(1)
  364. # all the tools are selected by default
  365. self.ui.tools_table.selectColumn(0)
  366. self.ui.tools_table.resizeColumnsToContents()
  367. self.ui.tools_table.resizeRowsToContents()
  368. vertical_header = self.ui.tools_table.verticalHeader()
  369. # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
  370. vertical_header.hide()
  371. self.ui.tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  372. horizontal_header = self.ui.tools_table.horizontalHeader()
  373. horizontal_header.setMinimumSectionSize(10)
  374. horizontal_header.setDefaultSectionSize(70)
  375. horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
  376. horizontal_header.resizeSection(0, 20)
  377. horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
  378. horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
  379. horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
  380. horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed)
  381. horizontal_header.resizeSection(5, 17)
  382. self.ui.tools_table.setColumnWidth(5, 17)
  383. # horizontal_header.setStretchLastSection(True)
  384. # horizontal_header.setColumnWidth(2, QtWidgets.QHeaderView.ResizeToContents)
  385. # horizontal_header.setStretchLastSection(True)
  386. self.ui.tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  387. self.ui.tools_table.setSortingEnabled(False)
  388. self.ui.tools_table.setMinimumHeight(self.ui.tools_table.getHeight())
  389. self.ui.tools_table.setMaximumHeight(self.ui.tools_table.getHeight())
  390. if not self.drills:
  391. self.ui.tooldia_entry.hide()
  392. self.ui.generate_milling_button.hide()
  393. else:
  394. self.ui.tooldia_entry.show()
  395. self.ui.generate_milling_button.show()
  396. if not self.slots:
  397. self.ui.slot_tooldia_entry.hide()
  398. self.ui.generate_milling_slots_button.hide()
  399. else:
  400. self.ui.slot_tooldia_entry.show()
  401. self.ui.generate_milling_slots_button.show()
  402. # set the text on tool_data_label after loading the object
  403. sel_items = self.ui.tools_table.selectedItems()
  404. sel_rows = [it.row() for it in sel_items]
  405. if len(sel_rows) > 1:
  406. self.ui.tool_data_label.setText(
  407. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  408. )
  409. self.ui_connect()
  410. def set_ui(self, ui):
  411. """
  412. Configures the user interface for this object.
  413. Connects options to form fields.
  414. :param ui: User interface object.
  415. :type ui: ExcellonObjectUI
  416. :return: None
  417. """
  418. FlatCAMObj.set_ui(self, ui)
  419. log.debug("ExcellonObject.set_ui()")
  420. self.units = self.app.defaults['units'].upper()
  421. self.form_fields.update({
  422. "plot": self.ui.plot_cb,
  423. "solid": self.ui.solid_cb,
  424. "operation": self.ui.operation_radio,
  425. "milling_type": self.ui.milling_type_radio,
  426. "milling_dia": self.ui.mill_dia_entry,
  427. "cutz": self.ui.cutz_entry,
  428. "multidepth": self.ui.mpass_cb,
  429. "depthperpass": self.ui.maxdepth_entry,
  430. "travelz": self.ui.travelz_entry,
  431. "feedrate_z": self.ui.feedrate_z_entry,
  432. "feedrate": self.ui.xyfeedrate_entry,
  433. "feedrate_rapid": self.ui.feedrate_rapid_entry,
  434. "tooldia": self.ui.tooldia_entry,
  435. "slot_tooldia": self.ui.slot_tooldia_entry,
  436. "toolchange": self.ui.toolchange_cb,
  437. "toolchangez": self.ui.toolchangez_entry,
  438. "extracut": self.ui.extracut_cb,
  439. "extracut_length": self.ui.e_cut_entry,
  440. "spindlespeed": self.ui.spindlespeed_entry,
  441. "dwell": self.ui.dwell_cb,
  442. "dwelltime": self.ui.dwelltime_entry,
  443. "startz": self.ui.estartz_entry,
  444. "endz": self.ui.endz_entry,
  445. "endxy": self.ui.endxy_entry,
  446. "offset": self.ui.offset_entry,
  447. "ppname_e": self.ui.pp_excellon_name_cb,
  448. "ppname_g": self.ui.pp_geo_name_cb,
  449. "z_pdepth": self.ui.pdepth_entry,
  450. "feedrate_probe": self.ui.feedrate_probe_entry,
  451. # "gcode_type": self.ui.excellon_gcode_type_radio,
  452. "area_exclusion": self.ui.exclusion_cb,
  453. "area_shape": self.ui.area_shape_radio,
  454. "area_strategy": self.ui.strategy_radio,
  455. "area_overz": self.ui.over_z_entry,
  456. })
  457. self.name2option = {
  458. "e_operation": "operation",
  459. "e_milling_type": "milling_type",
  460. "e_milling_dia": "milling_dia",
  461. "e_cutz": "cutz",
  462. "e_multidepth": "multidepth",
  463. "e_depthperpass": "depthperpass",
  464. "e_travelz": "travelz",
  465. "e_feedratexy": "feedrate",
  466. "e_feedratez": "feedrate_z",
  467. "e_fr_rapid": "feedrate_rapid",
  468. "e_extracut": "extracut",
  469. "e_extracut_length": "extracut_length",
  470. "e_spindlespeed": "spindlespeed",
  471. "e_dwell": "dwell",
  472. "e_dwelltime": "dwelltime",
  473. "e_offset": "offset",
  474. }
  475. # populate Excellon preprocessor combobox list
  476. for name in list(self.app.preprocessors.keys()):
  477. # the HPGL preprocessor is only for Geometry not for Excellon job therefore don't add it
  478. if name == 'hpgl':
  479. continue
  480. self.ui.pp_excellon_name_cb.addItem(name)
  481. # populate Geometry (milling) preprocessor combobox list
  482. for name in list(self.app.preprocessors.keys()):
  483. self.ui.pp_geo_name_cb.addItem(name)
  484. # Fill form fields
  485. self.to_form()
  486. # update the changes in UI depending on the selected preprocessor in Preferences
  487. # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
  488. # self.ui.pp_excellon_name_cb combobox
  489. self.on_pp_changed()
  490. # Show/Hide Advanced Options
  491. if self.app.defaults["global_app_level"] == 'b':
  492. self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
  493. self.ui.tools_table.setColumnHidden(4, True)
  494. self.ui.tools_table.setColumnHidden(5, True)
  495. self.ui.estartz_label.hide()
  496. self.ui.estartz_entry.hide()
  497. self.ui.feedrate_rapid_label.hide()
  498. self.ui.feedrate_rapid_entry.hide()
  499. self.ui.pdepth_label.hide()
  500. self.ui.pdepth_entry.hide()
  501. self.ui.feedrate_probe_label.hide()
  502. self.ui.feedrate_probe_entry.hide()
  503. else:
  504. self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
  505. assert isinstance(self.ui, ExcellonObjectUI), \
  506. "Expected a ExcellonObjectUI, got %s" % type(self.ui)
  507. self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
  508. self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
  509. self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click)
  510. self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click)
  511. self.ui.generate_milling_slots_button.clicked.connect(self.on_generate_milling_slots_button_click)
  512. self.ui.add_area_button.clicked.connect(self.on_add_area_click)
  513. self.ui.delete_area_button.clicked.connect(self.on_clear_area_click)
  514. self.on_operation_type(val='drill')
  515. self.ui.operation_radio.activated_custom.connect(self.on_operation_type)
  516. self.ui.pp_excellon_name_cb.activated.connect(self.on_pp_changed)
  517. self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
  518. self.units_found = self.app.defaults['units']
  519. # ########################################
  520. # #######3 TEMP SETTINGS #################
  521. # ########################################
  522. self.ui.operation_radio.set_value("drill")
  523. self.ui.operation_radio.setEnabled(False)
  524. def ui_connect(self):
  525. # selective plotting
  526. for row in range(self.ui.tools_table.rowCount() - 2):
  527. self.ui.tools_table.cellWidget(row, 5).clicked.connect(self.on_plot_cb_click_table)
  528. self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
  529. # rows selected
  530. self.ui.tools_table.clicked.connect(self.on_row_selection_change)
  531. self.ui.tools_table.horizontalHeader().sectionClicked.connect(self.on_row_selection_change)
  532. # value changed in the particular parameters of a tool
  533. for key, option in self.name2option.items():
  534. current_widget = self.form_fields[option]
  535. if isinstance(current_widget, FCCheckBox):
  536. current_widget.stateChanged.connect(self.form_to_storage)
  537. if isinstance(current_widget, RadioSet):
  538. current_widget.activated_custom.connect(self.form_to_storage)
  539. elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
  540. current_widget.returnPressed.connect(self.form_to_storage)
  541. def ui_disconnect(self):
  542. # selective plotting
  543. for row in range(self.ui.tools_table.rowCount()):
  544. try:
  545. self.ui.tools_table.cellWidget(row, 5).clicked.disconnect()
  546. except (TypeError, AttributeError):
  547. pass
  548. try:
  549. self.ui.plot_cb.stateChanged.disconnect()
  550. except (TypeError, AttributeError):
  551. pass
  552. # rows selected
  553. try:
  554. self.ui.tools_table.clicked.disconnect()
  555. except (TypeError, AttributeError):
  556. pass
  557. try:
  558. self.ui.tools_table.horizontalHeader().sectionClicked.disconnect()
  559. except (TypeError, AttributeError):
  560. pass
  561. # value changed in the particular parameters of a tool
  562. for key, option in self.name2option.items():
  563. current_widget = self.form_fields[option]
  564. if isinstance(current_widget, FCCheckBox):
  565. try:
  566. current_widget.stateChanged.disconnect(self.form_to_storage)
  567. except (TypeError, ValueError):
  568. pass
  569. if isinstance(current_widget, RadioSet):
  570. try:
  571. current_widget.activated_custom.disconnect(self.form_to_storage)
  572. except (TypeError, ValueError):
  573. pass
  574. elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
  575. try:
  576. current_widget.returnPressed.disconnect(self.form_to_storage)
  577. except (TypeError, ValueError):
  578. pass
  579. def on_row_selection_change(self):
  580. self.ui_disconnect()
  581. sel_rows = []
  582. sel_items = self.ui.tools_table.selectedItems()
  583. for it in sel_items:
  584. sel_rows.append(it.row())
  585. if not sel_rows:
  586. self.ui.tool_data_label.setText(
  587. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
  588. )
  589. self.ui.generate_cnc_button.setDisabled(True)
  590. self.ui.generate_milling_button.setDisabled(True)
  591. self.ui.generate_milling_slots_button.setDisabled(True)
  592. self.ui_connect()
  593. return
  594. else:
  595. self.ui.generate_cnc_button.setDisabled(False)
  596. self.ui.generate_milling_button.setDisabled(False)
  597. self.ui.generate_milling_slots_button.setDisabled(False)
  598. if len(sel_rows) == 1:
  599. # update the QLabel that shows for which Tool we have the parameters in the UI form
  600. tooluid = int(self.ui.tools_table.item(sel_rows[0], 0).text())
  601. self.ui.tool_data_label.setText(
  602. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
  603. )
  604. else:
  605. self.ui.tool_data_label.setText(
  606. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  607. )
  608. for c_row in sel_rows:
  609. # populate the form with the data from the tool associated with the row parameter
  610. try:
  611. item = self.ui.tools_table.item(c_row, 0)
  612. if type(item) is not None:
  613. tooluid = item.text()
  614. self.storage_to_form(self.tools[str(tooluid)]['data'])
  615. else:
  616. self.ui_connect()
  617. return
  618. except Exception as e:
  619. log.debug("Tool missing. Add a tool in Geo Tool Table. %s" % str(e))
  620. self.ui_connect()
  621. return
  622. self.ui_connect()
  623. def storage_to_form(self, dict_storage):
  624. for form_key in self.form_fields:
  625. for storage_key in dict_storage:
  626. if form_key == storage_key and form_key not in \
  627. ["toolchange", "toolchangez", "startz", "endz", "ppname_e", "ppname_g"]:
  628. try:
  629. self.form_fields[form_key].set_value(dict_storage[form_key])
  630. except Exception as e:
  631. log.debug("ExcellonObject.storage_to_form() --> %s" % str(e))
  632. pass
  633. def form_to_storage(self):
  634. if self.ui.tools_table.rowCount() == 0:
  635. # there is no tool in tool table so we can't save the GUI elements values to storage
  636. return
  637. self.ui_disconnect()
  638. widget_changed = self.sender()
  639. wdg_objname = widget_changed.objectName()
  640. option_changed = self.name2option[wdg_objname]
  641. # row = self.ui.tools_table.currentRow()
  642. rows = sorted(set(index.row() for index in self.ui.tools_table.selectedIndexes()))
  643. for row in rows:
  644. if row < 0:
  645. row = 0
  646. tooluid_item = int(self.ui.tools_table.item(row, 0).text())
  647. for tooluid_key, tooluid_val in self.tools.items():
  648. if int(tooluid_key) == tooluid_item:
  649. new_option_value = self.form_fields[option_changed].get_value()
  650. if option_changed in tooluid_val:
  651. tooluid_val[option_changed] = new_option_value
  652. if option_changed in tooluid_val['data']:
  653. tooluid_val['data'][option_changed] = new_option_value
  654. self.ui_connect()
  655. def on_operation_type(self, val):
  656. if val == 'mill':
  657. self.ui.mill_type_label.show()
  658. self.ui.milling_type_radio.show()
  659. self.ui.mill_dia_label.show()
  660. self.ui.mill_dia_entry.show()
  661. self.ui.frxylabel.show()
  662. self.ui.xyfeedrate_entry.show()
  663. self.ui.extracut_cb.show()
  664. self.ui.e_cut_entry.show()
  665. # if 'laser' not in self.ui.pp_excellon_name_cb.get_value().lower():
  666. # self.ui.mpass_cb.show()
  667. # self.ui.maxdepth_entry.show()
  668. else:
  669. self.ui.mill_type_label.hide()
  670. self.ui.milling_type_radio.hide()
  671. self.ui.mill_dia_label.hide()
  672. self.ui.mill_dia_entry.hide()
  673. # self.ui.mpass_cb.hide()
  674. # self.ui.maxdepth_entry.hide()
  675. self.ui.frxylabel.hide()
  676. self.ui.xyfeedrate_entry.hide()
  677. self.ui.extracut_cb.hide()
  678. self.ui.e_cut_entry.hide()
  679. def get_selected_tools_list(self):
  680. """
  681. Returns the keys to the self.tools dictionary corresponding
  682. to the selections on the tool list in the GUI.
  683. :return: List of tools.
  684. :rtype: list
  685. """
  686. return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
  687. def get_selected_tools_table_items(self):
  688. """
  689. Returns a list of lists, each list in the list is made out of row elements
  690. :return: List of table_tools items.
  691. :rtype: list
  692. """
  693. table_tools_items = []
  694. for x in self.ui.tools_table.selectedItems():
  695. # from the columnCount we subtract a value of 1 which represent the last column (plot column)
  696. # which does not have text
  697. txt = ''
  698. elem = []
  699. for column in range(0, self.ui.tools_table.columnCount() - 1):
  700. try:
  701. txt = self.ui.tools_table.item(x.row(), column).text()
  702. except AttributeError:
  703. try:
  704. txt = self.ui.tools_table.cellWidget(x.row(), column).currentText()
  705. except AttributeError:
  706. pass
  707. elem.append(txt)
  708. table_tools_items.append(deepcopy(elem))
  709. # table_tools_items.append([self.ui.tools_table.item(x.row(), column).text()
  710. # for column in range(0, self.ui.tools_table.columnCount() - 1)])
  711. for item in table_tools_items:
  712. item[0] = str(item[0])
  713. return table_tools_items
  714. def export_excellon(self, whole, fract, e_zeros=None, form='dec', factor=1, slot_type='routing'):
  715. """
  716. Returns two values, first is a boolean , if 1 then the file has slots and second contain the Excellon code
  717. :return: has_slots and Excellon_code
  718. """
  719. excellon_code = ''
  720. # store here if the file has slots, return 1 if any slots, 0 if only drills
  721. has_slots = 0
  722. # drills processing
  723. try:
  724. if self.drills:
  725. length = whole + fract
  726. for tool in self.tools:
  727. excellon_code += 'T0%s\n' % str(tool) if int(tool) < 10 else 'T%s\n' % str(tool)
  728. for drill in self.drills:
  729. if form == 'dec' and tool == drill['tool']:
  730. drill_x = drill['point'].x * factor
  731. drill_y = drill['point'].y * factor
  732. excellon_code += "X{:.{dec}f}Y{:.{dec}f}\n".format(drill_x, drill_y, dec=fract)
  733. elif e_zeros == 'LZ' and tool == drill['tool']:
  734. drill_x = drill['point'].x * factor
  735. drill_y = drill['point'].y * factor
  736. exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract)
  737. exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract)
  738. # extract whole part and decimal part
  739. exc_x_formatted = exc_x_formatted.partition('.')
  740. exc_y_formatted = exc_y_formatted.partition('.')
  741. # left padd the 'whole' part with zeros
  742. x_whole = exc_x_formatted[0].rjust(whole, '0')
  743. y_whole = exc_y_formatted[0].rjust(whole, '0')
  744. # restore the coordinate padded in the left with 0 and added the decimal part
  745. # without the decinal dot
  746. exc_x_formatted = x_whole + exc_x_formatted[2]
  747. exc_y_formatted = y_whole + exc_y_formatted[2]
  748. excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
  749. yform=exc_y_formatted)
  750. elif tool == drill['tool']:
  751. drill_x = drill['point'].x * factor
  752. drill_y = drill['point'].y * factor
  753. exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract).replace('.', '')
  754. exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract).replace('.', '')
  755. # pad with rear zeros
  756. exc_x_formatted.ljust(length, '0')
  757. exc_y_formatted.ljust(length, '0')
  758. excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
  759. yform=exc_y_formatted)
  760. except Exception as e:
  761. log.debug(str(e))
  762. # slots processing
  763. try:
  764. if self.slots:
  765. has_slots = 1
  766. for tool in self.tools:
  767. excellon_code += 'G05\n'
  768. if int(tool) < 10:
  769. excellon_code += 'T0' + str(tool) + '\n'
  770. else:
  771. excellon_code += 'T' + str(tool) + '\n'
  772. for slot in self.slots:
  773. if form == 'dec' and tool == slot['tool']:
  774. start_slot_x = slot['start'].x * factor
  775. start_slot_y = slot['start'].y * factor
  776. stop_slot_x = slot['stop'].x * factor
  777. stop_slot_y = slot['stop'].y * factor
  778. if slot_type == 'routing':
  779. excellon_code += "G00X{:.{dec}f}Y{:.{dec}f}\nM15\n".format(start_slot_x,
  780. start_slot_y,
  781. dec=fract)
  782. excellon_code += "G01X{:.{dec}f}Y{:.{dec}f}\nM16\n".format(stop_slot_x,
  783. stop_slot_y,
  784. dec=fract)
  785. elif slot_type == 'drilling':
  786. excellon_code += "X{:.{dec}f}Y{:.{dec}f}G85X{:.{dec}f}Y{:.{dec}f}\nG05\n".format(
  787. start_slot_x, start_slot_y, stop_slot_x, stop_slot_y, dec=fract
  788. )
  789. elif e_zeros == 'LZ' and tool == slot['tool']:
  790. start_slot_x = slot['start'].x * factor
  791. start_slot_y = slot['start'].y * factor
  792. stop_slot_x = slot['stop'].x * factor
  793. stop_slot_y = slot['stop'].y * factor
  794. start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
  795. start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
  796. stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
  797. stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
  798. # extract whole part and decimal part
  799. start_slot_x_formatted = start_slot_x_formatted.partition('.')
  800. start_slot_y_formatted = start_slot_y_formatted.partition('.')
  801. stop_slot_x_formatted = stop_slot_x_formatted.partition('.')
  802. stop_slot_y_formatted = stop_slot_y_formatted.partition('.')
  803. # left padd the 'whole' part with zeros
  804. start_x_whole = start_slot_x_formatted[0].rjust(whole, '0')
  805. start_y_whole = start_slot_y_formatted[0].rjust(whole, '0')
  806. stop_x_whole = stop_slot_x_formatted[0].rjust(whole, '0')
  807. stop_y_whole = stop_slot_y_formatted[0].rjust(whole, '0')
  808. # restore the coordinate padded in the left with 0 and added the decimal part
  809. # without the decinal dot
  810. start_slot_x_formatted = start_x_whole + start_slot_x_formatted[2]
  811. start_slot_y_formatted = start_y_whole + start_slot_y_formatted[2]
  812. stop_slot_x_formatted = stop_x_whole + stop_slot_x_formatted[2]
  813. stop_slot_y_formatted = stop_y_whole + stop_slot_y_formatted[2]
  814. if slot_type == 'routing':
  815. excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
  816. ystart=start_slot_y_formatted)
  817. excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
  818. ystop=stop_slot_y_formatted)
  819. elif slot_type == 'drilling':
  820. excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
  821. xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
  822. xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
  823. )
  824. elif tool == slot['tool']:
  825. start_slot_x = slot['start'].x * factor
  826. start_slot_y = slot['start'].y * factor
  827. stop_slot_x = slot['stop'].x * factor
  828. stop_slot_y = slot['stop'].y * factor
  829. length = whole + fract
  830. start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
  831. start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
  832. stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
  833. stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
  834. # pad with rear zeros
  835. start_slot_x_formatted.ljust(length, '0')
  836. start_slot_y_formatted.ljust(length, '0')
  837. stop_slot_x_formatted.ljust(length, '0')
  838. stop_slot_y_formatted.ljust(length, '0')
  839. if slot_type == 'routing':
  840. excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
  841. ystart=start_slot_y_formatted)
  842. excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
  843. ystop=stop_slot_y_formatted)
  844. elif slot_type == 'drilling':
  845. excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
  846. xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
  847. xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
  848. )
  849. except Exception as e:
  850. log.debug(str(e))
  851. if not self.drills and not self.slots:
  852. log.debug("FlatCAMObj.ExcellonObject.export_excellon() --> Excellon Object is empty: no drills, no slots.")
  853. return 'fail'
  854. return has_slots, excellon_code
  855. def generate_milling_drills(self, tools=None, outname=None, tooldia=None, plot=False, use_thread=False):
  856. """
  857. Note: This method is a good template for generic operations as
  858. it takes it's options from parameters or otherwise from the
  859. object's options and returns a (success, msg) tuple as feedback
  860. for shell operations.
  861. :return: Success/failure condition tuple (bool, str).
  862. :rtype: tuple
  863. """
  864. # Get the tools from the list. These are keys
  865. # to self.tools
  866. if tools is None:
  867. tools = self.get_selected_tools_list()
  868. if outname is None:
  869. outname = self.options["name"] + "_mill"
  870. if tooldia is None:
  871. tooldia = float(self.options["tooldia"])
  872. # Sort tools by diameter. items() -> [('name', diameter), ...]
  873. # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
  874. sort = []
  875. for k, v in self.tools.items():
  876. sort.append((k, v.get('C')))
  877. sorted_tools = sorted(sort, key=lambda t1: t1[1])
  878. if tools == "all":
  879. tools = [i[0] for i in sorted_tools] # List if ordered tool names.
  880. log.debug("Tools 'all' and sorted are: %s" % str(tools))
  881. if len(tools) == 0:
  882. self.app.inform.emit('[ERROR_NOTCL] %s' %
  883. _("Please select one or more tools from the list and try again."))
  884. return False, "Error: No tools."
  885. for tool in tools:
  886. if tooldia > self.tools[tool]["C"]:
  887. self.app.inform.emit(
  888. '[ERROR_NOTCL] %s %s: %s' % (
  889. _("Milling tool for DRILLS is larger than hole size. Cancelled."),
  890. _("Tool"),
  891. str(tool)
  892. )
  893. )
  894. return False, "Error: Milling tool is larger than hole."
  895. def geo_init(geo_obj, app_obj):
  896. assert geo_obj.kind == 'geometry', "Initializer expected a GeometryObject, got %s" % type(geo_obj)
  897. # ## Add properties to the object
  898. # get the tool_table items in a list of row items
  899. tool_table_items = self.get_selected_tools_table_items()
  900. # insert an information only element in the front
  901. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  902. geo_obj.options['Tools_in_use'] = tool_table_items
  903. geo_obj.options['type'] = 'Excellon Geometry'
  904. geo_obj.options["cnctooldia"] = str(tooldia)
  905. geo_obj.solid_geometry = []
  906. # in case that the tool used has the same diameter with the hole, and since the maximum resolution
  907. # for FlatCAM is 6 decimals,
  908. # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
  909. for hole in self.drills:
  910. if hole['tool'] in tools:
  911. buffer_value = self.tools[hole['tool']]["C"] / 2 - tooldia / 2
  912. if buffer_value == 0:
  913. geo_obj.solid_geometry.append(
  914. Point(hole['point']).buffer(0.0000001).exterior)
  915. else:
  916. geo_obj.solid_geometry.append(
  917. Point(hole['point']).buffer(buffer_value).exterior)
  918. if use_thread:
  919. def geo_thread(app_obj):
  920. app_obj.new_object("geometry", outname, geo_init, plot=plot)
  921. # Create a promise with the new name
  922. self.app.collection.promise(outname)
  923. # Send to worker
  924. self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
  925. else:
  926. self.app.new_object("geometry", outname, geo_init, plot=plot)
  927. return True, ""
  928. def generate_milling_slots(self, tools=None, outname=None, tooldia=None, plot=True, use_thread=False):
  929. """
  930. Note: This method is a good template for generic operations as
  931. it takes it's options from parameters or otherwise from the
  932. object's options and returns a (success, msg) tuple as feedback
  933. for shell operations.
  934. :return: Success/failure condition tuple (bool, str).
  935. :rtype: tuple
  936. """
  937. # Get the tools from the list. These are keys
  938. # to self.tools
  939. if tools is None:
  940. tools = self.get_selected_tools_list()
  941. if outname is None:
  942. outname = self.options["name"] + "_mill"
  943. if tooldia is None:
  944. tooldia = float(self.options["slot_tooldia"])
  945. # Sort tools by diameter. items() -> [('name', diameter), ...]
  946. # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
  947. sort = []
  948. for k, v in self.tools.items():
  949. sort.append((k, v.get('C')))
  950. sorted_tools = sorted(sort, key=lambda t1: t1[1])
  951. if tools == "all":
  952. tools = [i[0] for i in sorted_tools] # List if ordered tool names.
  953. log.debug("Tools 'all' and sorted are: %s" % str(tools))
  954. if len(tools) == 0:
  955. self.app.inform.emit('[ERROR_NOTCL] %s' %
  956. _("Please select one or more tools from the list and try again."))
  957. return False, "Error: No tools."
  958. for tool in tools:
  959. # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
  960. adj_toolstable_tooldia = float('%.*f' % (self.decimals, float(tooldia)))
  961. adj_file_tooldia = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
  962. if adj_toolstable_tooldia > adj_file_tooldia + 0.0001:
  963. self.app.inform.emit('[ERROR_NOTCL] %s' %
  964. _("Milling tool for SLOTS is larger than hole size. Cancelled."))
  965. return False, "Error: Milling tool is larger than hole."
  966. def geo_init(geo_obj, app_obj):
  967. assert geo_obj.kind == 'geometry' "Initializer expected a GeometryObject, got %s" % type(geo_obj)
  968. # ## Add properties to the object
  969. # get the tool_table items in a list of row items
  970. tool_table_items = self.get_selected_tools_table_items()
  971. # insert an information only element in the front
  972. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  973. geo_obj.options['Tools_in_use'] = tool_table_items
  974. geo_obj.options['type'] = 'Excellon Geometry'
  975. geo_obj.options["cnctooldia"] = str(tooldia)
  976. geo_obj.solid_geometry = []
  977. # in case that the tool used has the same diameter with the hole, and since the maximum resolution
  978. # for FlatCAM is 6 decimals,
  979. # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
  980. for slot in self.slots:
  981. if slot['tool'] in tools:
  982. toolstable_tool = float('%.*f' % (self.decimals, float(tooldia)))
  983. file_tool = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
  984. # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
  985. # for the file_tool (tooldia actually)
  986. buffer_value = float(file_tool / 2) - float(toolstable_tool / 2) + 0.0001
  987. if buffer_value == 0:
  988. start = slot['start']
  989. stop = slot['stop']
  990. lines_string = LineString([start, stop])
  991. poly = lines_string.buffer(0.0000001, int(self.geo_steps_per_circle)).exterior
  992. geo_obj.solid_geometry.append(poly)
  993. else:
  994. start = slot['start']
  995. stop = slot['stop']
  996. lines_string = LineString([start, stop])
  997. poly = lines_string.buffer(buffer_value, int(self.geo_steps_per_circle)).exterior
  998. geo_obj.solid_geometry.append(poly)
  999. if use_thread:
  1000. def geo_thread(app_obj):
  1001. app_obj.new_object("geometry", outname + '_slot', geo_init, plot=plot)
  1002. # Create a promise with the new name
  1003. self.app.collection.promise(outname)
  1004. # Send to worker
  1005. self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
  1006. else:
  1007. self.app.new_object("geometry", outname + '_slot', geo_init, plot=plot)
  1008. return True, ""
  1009. def on_generate_milling_button_click(self, *args):
  1010. self.app.defaults.report_usage("excellon_on_create_milling_drills button")
  1011. self.read_form()
  1012. self.generate_milling_drills(use_thread=False)
  1013. def on_generate_milling_slots_button_click(self, *args):
  1014. self.app.defaults.report_usage("excellon_on_create_milling_slots_button")
  1015. self.read_form()
  1016. self.generate_milling_slots(use_thread=False)
  1017. def on_pp_changed(self):
  1018. current_pp = self.ui.pp_excellon_name_cb.get_value()
  1019. if "toolchange_probe" in current_pp.lower():
  1020. self.ui.pdepth_entry.setVisible(True)
  1021. self.ui.pdepth_label.show()
  1022. self.ui.feedrate_probe_entry.setVisible(True)
  1023. self.ui.feedrate_probe_label.show()
  1024. else:
  1025. self.ui.pdepth_entry.setVisible(False)
  1026. self.ui.pdepth_label.hide()
  1027. self.ui.feedrate_probe_entry.setVisible(False)
  1028. self.ui.feedrate_probe_label.hide()
  1029. if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
  1030. self.ui.feedrate_rapid_label.show()
  1031. self.ui.feedrate_rapid_entry.show()
  1032. else:
  1033. self.ui.feedrate_rapid_label.hide()
  1034. self.ui.feedrate_rapid_entry.hide()
  1035. if 'laser' in current_pp.lower():
  1036. self.ui.cutzlabel.hide()
  1037. self.ui.cutz_entry.hide()
  1038. try:
  1039. self.ui.mpass_cb.hide()
  1040. self.ui.maxdepth_entry.hide()
  1041. except AttributeError:
  1042. pass
  1043. if 'marlin' in current_pp.lower():
  1044. self.ui.travelzlabel.setText('%s:' % _("Focus Z"))
  1045. self.ui.endz_label.show()
  1046. self.ui.endz_entry.show()
  1047. else:
  1048. self.ui.travelzlabel.hide()
  1049. self.ui.travelz_entry.hide()
  1050. self.ui.endz_label.hide()
  1051. self.ui.endz_entry.hide()
  1052. try:
  1053. self.ui.frzlabel.hide()
  1054. self.ui.feedrate_z_entry.hide()
  1055. except AttributeError:
  1056. pass
  1057. self.ui.dwell_cb.hide()
  1058. self.ui.dwelltime_entry.hide()
  1059. self.ui.spindle_label.setText('%s:' % _("Laser Power"))
  1060. try:
  1061. self.ui.tool_offset_label.hide()
  1062. self.ui.offset_entry.hide()
  1063. except AttributeError:
  1064. pass
  1065. else:
  1066. self.ui.cutzlabel.show()
  1067. self.ui.cutz_entry.show()
  1068. try:
  1069. self.ui.mpass_cb.show()
  1070. self.ui.maxdepth_entry.show()
  1071. except AttributeError:
  1072. pass
  1073. self.ui.travelzlabel.setText('%s:' % _('Travel Z'))
  1074. self.ui.travelzlabel.show()
  1075. self.ui.travelz_entry.show()
  1076. self.ui.endz_label.show()
  1077. self.ui.endz_entry.show()
  1078. try:
  1079. self.ui.frzlabel.show()
  1080. self.ui.feedrate_z_entry.show()
  1081. except AttributeError:
  1082. pass
  1083. self.ui.dwell_cb.show()
  1084. self.ui.dwelltime_entry.show()
  1085. self.ui.spindle_label.setText('%s:' % _('Spindle speed'))
  1086. try:
  1087. self.ui.tool_offset_lbl.show()
  1088. self.ui.offset_entry.show()
  1089. except AttributeError:
  1090. pass
  1091. def on_create_cncjob_button_click(self, *args):
  1092. self.app.defaults.report_usage("excellon_on_create_cncjob_button")
  1093. self.read_form()
  1094. # Get the tools from the list
  1095. tools = self.get_selected_tools_list()
  1096. if len(tools) == 0:
  1097. # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in
  1098. # tool number) it means that there are 3 rows (1 tool and 2 totals).
  1099. # in this case regardless of the selection status of that tool, use it.
  1100. if self.ui.tools_table.rowCount() == 3:
  1101. tools.append(self.ui.tools_table.item(0, 0).text())
  1102. else:
  1103. self.app.inform.emit('[ERROR_NOTCL] %s' %
  1104. _("Please select one or more tools from the list and try again."))
  1105. return
  1106. xmin = self.options['xmin']
  1107. ymin = self.options['ymin']
  1108. xmax = self.options['xmax']
  1109. ymax = self.options['ymax']
  1110. job_name = self.options["name"] + "_cnc"
  1111. pp_excellon_name = self.options["ppname_e"]
  1112. # Object initialization function for app.new_object()
  1113. def job_init(job_obj, app_obj):
  1114. assert job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
  1115. # get the tool_table items in a list of row items
  1116. tool_table_items = self.get_selected_tools_table_items()
  1117. # insert an information only element in the front
  1118. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1119. # ## Add properties to the object
  1120. job_obj.origin_kind = 'excellon'
  1121. job_obj.options['Tools_in_use'] = tool_table_items
  1122. job_obj.options['type'] = 'Excellon'
  1123. job_obj.options['ppname_e'] = pp_excellon_name
  1124. job_obj.multidepth = self.options["multidepth"]
  1125. job_obj.z_depthpercut = self.options["depthperpass"]
  1126. job_obj.z_move = float(self.options["travelz"])
  1127. job_obj.feedrate = float(self.options["feedrate_z"])
  1128. job_obj.z_feedrate = float(self.options["feedrate_z"])
  1129. job_obj.feedrate_rapid = float(self.options["feedrate_rapid"])
  1130. job_obj.spindlespeed = float(self.options["spindlespeed"]) if self.options["spindlespeed"] != 0 else None
  1131. job_obj.spindledir = self.app.defaults['excellon_spindledir']
  1132. job_obj.dwell = self.options["dwell"]
  1133. job_obj.dwelltime = float(self.options["dwelltime"])
  1134. job_obj.pp_excellon_name = pp_excellon_name
  1135. job_obj.toolchange_xy_type = "excellon"
  1136. job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
  1137. job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
  1138. job_obj.options['xmin'] = xmin
  1139. job_obj.options['ymin'] = ymin
  1140. job_obj.options['xmax'] = xmax
  1141. job_obj.options['ymax'] = ymax
  1142. job_obj.z_pdepth = float(self.options["z_pdepth"])
  1143. job_obj.feedrate_probe = float(self.options["feedrate_probe"])
  1144. job_obj.z_cut = float(self.options['cutz'])
  1145. job_obj.toolchange = self.options["toolchange"]
  1146. job_obj.xy_toolchange = self.app.defaults["excellon_toolchangexy"]
  1147. job_obj.z_toolchange = float(self.options["toolchangez"])
  1148. job_obj.startz = float(self.options["startz"]) if self.options["startz"] else None
  1149. job_obj.endz = float(self.options["endz"])
  1150. job_obj.xy_end = self.options["endxy"]
  1151. job_obj.excellon_optimization_type = self.app.defaults["excellon_optimization_type"]
  1152. tools_csv = ','.join(tools)
  1153. ret_val = job_obj.generate_from_excellon_by_tool(self, tools_csv, use_ui=True)
  1154. if ret_val == 'fail':
  1155. return 'fail'
  1156. job_obj.gcode_parse()
  1157. job_obj.create_geometry()
  1158. # To be run in separate thread
  1159. def job_thread(app_obj):
  1160. with self.app.proc_container.new(_("Generating CNC Code")):
  1161. app_obj.new_object("cncjob", job_name, job_init)
  1162. # Create promise for the new name.
  1163. self.app.collection.promise(job_name)
  1164. # Send to worker
  1165. # self.app.worker.add_task(job_thread, [self.app])
  1166. self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
  1167. def convert_units(self, units):
  1168. log.debug("FlatCAMObj.ExcellonObject.convert_units()")
  1169. Excellon.convert_units(self, units)
  1170. # factor = Excellon.convert_units(self, units)
  1171. # self.options['drillz'] = float(self.options['drillz']) * factor
  1172. # self.options['travelz'] = float(self.options['travelz']) * factor
  1173. # self.options['feedrate'] = float(self.options['feedrate']) * factor
  1174. # self.options['feedrate_rapid'] = float(self.options['feedrate_rapid']) * factor
  1175. # self.options['toolchangez'] = float(self.options['toolchangez']) * factor
  1176. #
  1177. # if self.app.defaults["excellon_toolchangexy"] == '':
  1178. # self.options['toolchangexy'] = "0.0, 0.0"
  1179. # else:
  1180. # coords_xy = [float(eval(coord)) for coord in self.app.defaults["excellon_toolchangexy"].split(",")]
  1181. # if len(coords_xy) < 2:
  1182. # self.app.inform.emit('[ERROR] %s' % _("The Toolchange X,Y field in Edit -> Preferences has to be "
  1183. # "in the format (x, y) \n"
  1184. # "but now there is only one value, not two. "))
  1185. # return 'fail'
  1186. # coords_xy[0] *= factor
  1187. # coords_xy[1] *= factor
  1188. # self.options['toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1])
  1189. #
  1190. # if self.options['startz'] is not None:
  1191. # self.options['startz'] = float(self.options['startz']) * factor
  1192. # self.options['endz'] = float(self.options['endz']) * factor
  1193. def on_add_area_click(self):
  1194. shape_button = self.ui.area_shape_radio
  1195. overz_button = self.ui.over_z_entry
  1196. strategy_radio = self.ui.strategy_radio
  1197. cnc_button = self.ui.generate_cnc_button
  1198. solid_geo = self.solid_geometry
  1199. obj_type = self.kind
  1200. self.app.exc_areas.on_add_area_click(
  1201. shape_button=shape_button, overz_button=overz_button, cnc_button=cnc_button, strategy_radio=strategy_radio,
  1202. solid_geo=solid_geo, obj_type=obj_type)
  1203. def on_clear_area_click(self):
  1204. self.app.exc_areas.on_clear_area_click()
  1205. def on_solid_cb_click(self, *args):
  1206. if self.muted_ui:
  1207. return
  1208. self.read_form_item('solid')
  1209. self.plot()
  1210. def on_plot_cb_click(self, *args):
  1211. if self.muted_ui:
  1212. return
  1213. self.plot()
  1214. self.read_form_item('plot')
  1215. self.ui_disconnect()
  1216. cb_flag = self.ui.plot_cb.isChecked()
  1217. for row in range(self.ui.tools_table.rowCount() - 2):
  1218. table_cb = self.ui.tools_table.cellWidget(row, 5)
  1219. if cb_flag:
  1220. table_cb.setChecked(True)
  1221. else:
  1222. table_cb.setChecked(False)
  1223. self.ui_connect()
  1224. def on_plot_cb_click_table(self):
  1225. # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
  1226. self.ui_disconnect()
  1227. # cw = self.sender()
  1228. # cw_index = self.ui.tools_table.indexAt(cw.pos())
  1229. # cw_row = cw_index.row()
  1230. check_row = 0
  1231. self.shapes.clear(update=True)
  1232. for tool_key in self.tools:
  1233. solid_geometry = self.tools[tool_key]['solid_geometry']
  1234. # find the geo_tool_table row associated with the tool_key
  1235. for row in range(self.ui.tools_table.rowCount()):
  1236. tool_item = int(self.ui.tools_table.item(row, 0).text())
  1237. if tool_item == int(tool_key):
  1238. check_row = row
  1239. break
  1240. if self.ui.tools_table.cellWidget(check_row, 5).isChecked():
  1241. self.options['plot'] = True
  1242. # self.plot_element(element=solid_geometry, visible=True)
  1243. # Plot excellon (All polygons?)
  1244. if self.options["solid"]:
  1245. for geo in solid_geometry:
  1246. self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
  1247. visible=self.options['plot'],
  1248. layer=2)
  1249. else:
  1250. for geo in solid_geometry:
  1251. self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
  1252. for ints in geo.interiors:
  1253. self.add_shape(shape=ints, color='green', visible=self.options['plot'])
  1254. self.shapes.redraw()
  1255. # make sure that the general plot is disabled if one of the row plot's are disabled and
  1256. # if all the row plot's are enabled also enable the general plot checkbox
  1257. cb_cnt = 0
  1258. total_row = self.ui.tools_table.rowCount()
  1259. for row in range(total_row - 2):
  1260. if self.ui.tools_table.cellWidget(row, 5).isChecked():
  1261. cb_cnt += 1
  1262. else:
  1263. cb_cnt -= 1
  1264. if cb_cnt < total_row - 2:
  1265. self.ui.plot_cb.setChecked(False)
  1266. else:
  1267. self.ui.plot_cb.setChecked(True)
  1268. self.ui_connect()
  1269. def plot(self, visible=None, kind=None):
  1270. # Does all the required setup and returns False
  1271. # if the 'ptint' option is set to False.
  1272. if not FlatCAMObj.plot(self):
  1273. return
  1274. # try:
  1275. # # Plot Excellon (All polygons?)
  1276. # if self.options["solid"]:
  1277. # for tool in self.tools:
  1278. # for geo in self.tools[tool]['solid_geometry']:
  1279. # self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
  1280. # visible=self.options['plot'],
  1281. # layer=2)
  1282. # else:
  1283. # for tool in self.tools:
  1284. # for geo in self.tools[tool]['solid_geometry']:
  1285. # self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
  1286. # for ints in geo.interiors:
  1287. # self.add_shape(shape=ints, color='orange', visible=self.options['plot'])
  1288. #
  1289. # self.shapes.redraw()
  1290. # return
  1291. # except (ObjectDeleted, AttributeError, KeyError):
  1292. # self.shapes.clear(update=True)
  1293. # this stays for compatibility reasons, in case we try to open old projects
  1294. try:
  1295. __ = iter(self.solid_geometry)
  1296. except TypeError:
  1297. self.solid_geometry = [self.solid_geometry]
  1298. visible = visible if visible else self.options['plot']
  1299. try:
  1300. # Plot Excellon (All polygons?)
  1301. if self.options["solid"]:
  1302. for geo in self.solid_geometry:
  1303. self.add_shape(shape=geo,
  1304. color=self.outline_color,
  1305. face_color=self.fill_color,
  1306. visible=visible,
  1307. layer=2)
  1308. else:
  1309. for geo in self.solid_geometry:
  1310. self.add_shape(shape=geo.exterior, color='red', visible=visible)
  1311. for ints in geo.interiors:
  1312. self.add_shape(shape=ints, color='orange', visible=visible)
  1313. self.shapes.redraw()
  1314. except (ObjectDeleted, AttributeError):
  1315. self.shapes.clear(update=True)
  1316. def on_apply_param_to_all_clicked(self):
  1317. if self.ui.tools_table.rowCount() == 0:
  1318. # there is no tool in tool table so we can't save the GUI elements values to storage
  1319. log.debug("ExcellonObject.on_apply_param_to_all_clicked() --> no tool in Tools Table, aborting.")
  1320. return
  1321. self.ui_disconnect()
  1322. row = self.ui.tools_table.currentRow()
  1323. if row < 0:
  1324. row = 0
  1325. tooluid_item = int(self.ui.tools_table.item(row, 0).text())
  1326. temp_tool_data = {}
  1327. for tooluid_key, tooluid_val in self.tools.items():
  1328. if int(tooluid_key) == tooluid_item:
  1329. # this will hold the 'data' key of the self.tools[tool] dictionary that corresponds to
  1330. # the current row in the tool table
  1331. temp_tool_data = tooluid_val['data']
  1332. break
  1333. for tooluid_key, tooluid_val in self.tools.items():
  1334. tooluid_val['data'] = deepcopy(temp_tool_data)
  1335. self.app.inform.emit('[success] %s' % _("Current Tool parameters were applied to all tools."))
  1336. self.ui_connect()