ToolDrilling.py 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File by: Marius Adrian Stanciu (c) #
  4. # Date: 6/15/2020 #
  5. # License: MIT Licence #
  6. # ##########################################################
  7. from PyQt5 import QtWidgets, QtCore, QtGui
  8. from appTool import AppTool
  9. from appGUI.GUIElements import FCCheckBox, FCDoubleSpinner, RadioSet, FCTable, FCButton, \
  10. FCComboBox, OptionalInputSection, FCSpinner, NumericalEvalEntry, OptionalHideInputSection, FCLabel
  11. from appParsers.ParseExcellon import Excellon
  12. from copy import deepcopy
  13. import numpy as np
  14. import math
  15. from shapely.ops import unary_union
  16. from shapely.geometry import Point, LineString
  17. from matplotlib.backend_bases import KeyEvent as mpl_key_event
  18. import logging
  19. import gettext
  20. import appTranslation as fcTranslate
  21. import builtins
  22. import platform
  23. import re
  24. import traceback
  25. from Common import GracefulException as grace
  26. fcTranslate.apply_language('strings')
  27. if '_' not in builtins.__dict__:
  28. _ = gettext.gettext
  29. if platform.architecture()[0] == '64bit':
  30. from ortools.constraint_solver import pywrapcp
  31. from ortools.constraint_solver import routing_enums_pb2
  32. log = logging.getLogger('base')
  33. settings = QtCore.QSettings("Open Source", "FlatCAM")
  34. if settings.contains("machinist"):
  35. machinist_setting = settings.value('machinist', type=int)
  36. else:
  37. machinist_setting = 0
  38. class ToolDrilling(AppTool, Excellon):
  39. def __init__(self, app):
  40. self.app = app
  41. self.decimals = self.app.decimals
  42. AppTool.__init__(self, app)
  43. Excellon.__init__(self, geo_steps_per_circle=self.app.defaults["geometry_circle_steps"])
  44. # #############################################################################
  45. # ######################### Tool GUI ##########################################
  46. # #############################################################################
  47. self.t_ui = DrillingUI(layout=self.layout, app=self.app)
  48. self.toolName = self.t_ui.toolName
  49. # #############################################################################
  50. # ########################## VARIABLES ########################################
  51. # #############################################################################
  52. self.units = ''
  53. self.excellon_tools = {}
  54. self.tooluid = 0
  55. self.kind = "excellon"
  56. # dict that holds the object names and the option name
  57. # the key is the object name (defines in ObjectUI) for each UI element that is a parameter
  58. # particular for a tool and the value is the actual name of the option that the UI element is changing
  59. self.name2option = {}
  60. # store here the default data for Geometry Data
  61. self.default_data = {}
  62. self.obj_name = ""
  63. self.excellon_obj = None
  64. # this holds the resulting GCode
  65. self.total_gcode = ''
  66. # this holds the resulting Parsed Gcode
  67. self.total_gcode_parsed = []
  68. self.first_click = False
  69. self.cursor_pos = None
  70. self.mouse_is_dragging = False
  71. # store here the points for the "Polygon" area selection shape
  72. self.points = []
  73. self.mm = None
  74. self.mr = None
  75. self.kp = None
  76. # variable to store the total amount of drills per job
  77. self.tot_drill_cnt = 0
  78. self.tool_row = 0
  79. # variable to store the total amount of slots per job
  80. self.tot_slot_cnt = 0
  81. self.tool_row_slots = 0
  82. # variable to store the distance travelled
  83. self.travel_distance = 0.0
  84. self.grid_status_memory = self.app.ui.grid_snap_btn.isChecked()
  85. # store here the state of the exclusion checkbox state to be restored after building the UI
  86. # TODO add this in the sel.app.defaults dict and in Preferences
  87. self.exclusion_area_cb_is_checked = False
  88. # store here solid_geometry when there are tool with isolation job
  89. self.solid_geometry = []
  90. self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
  91. self.tooldia = None
  92. # multiprocessing
  93. self.pool = self.app.pool
  94. self.results = []
  95. # disconnect flags
  96. self.area_sel_disconnect_flag = False
  97. self.poly_sel_disconnect_flag = False
  98. self.form_fields = {
  99. "cutz": self.t_ui.cutz_entry,
  100. "multidepth": self.t_ui.mpass_cb,
  101. "depthperpass": self.t_ui.maxdepth_entry,
  102. "travelz": self.t_ui.travelz_entry,
  103. "feedrate_z": self.t_ui.feedrate_z_entry,
  104. "feedrate_rapid": self.t_ui.feedrate_rapid_entry,
  105. "spindlespeed": self.t_ui.spindlespeed_entry,
  106. "dwell": self.t_ui.dwell_cb,
  107. "dwelltime": self.t_ui.dwelltime_entry,
  108. "offset": self.t_ui.offset_entry,
  109. "drill_slots": self.t_ui.drill_slots_cb,
  110. "drill_overlap": self.t_ui.drill_overlap_entry,
  111. "last_drill": self.t_ui.last_drill_cb
  112. }
  113. self.name2option = {
  114. "e_cutz": "cutz",
  115. "e_multidepth": "multidepth",
  116. "e_depthperpass": "depthperpass",
  117. "e_travelz": "travelz",
  118. "e_feedratez": "feedrate_z",
  119. "e_fr_rapid": "feedrate_rapid",
  120. "e_spindlespeed": "spindlespeed",
  121. "e_dwell": "dwell",
  122. "e_dwelltime": "dwelltime",
  123. "e_offset": "offset",
  124. "e_drill_slots": "drill_slots",
  125. "e_drill_slots_overlap": "drill_overlap",
  126. "e_drill_last_drill": "last_drill",
  127. }
  128. self.old_tool_dia = None
  129. self.poly_drawn = False
  130. self.connect_signals_at_init()
  131. def install(self, icon=None, separator=None, **kwargs):
  132. AppTool.install(self, icon, separator, shortcut='Alt+D', **kwargs)
  133. def run(self, toggle=True):
  134. self.app.defaults.report_usage("ToolDrilling()")
  135. log.debug("ToolDrilling().run() was launched ...")
  136. if toggle:
  137. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  138. if self.app.ui.splitter.sizes()[0] == 0:
  139. self.app.ui.splitter.setSizes([1, 1])
  140. else:
  141. try:
  142. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  143. # if tab is populated with the tool but it does not have the focus, focus on it
  144. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  145. # focus on Tool Tab
  146. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  147. else:
  148. self.app.ui.splitter.setSizes([0, 1])
  149. except AttributeError:
  150. pass
  151. else:
  152. if self.app.ui.splitter.sizes()[0] == 0:
  153. self.app.ui.splitter.setSizes([1, 1])
  154. AppTool.run(self)
  155. self.set_tool_ui()
  156. self.on_object_changed()
  157. # self.build_tool_ui()
  158. # all the tools are selected by default
  159. self.t_ui.tools_table.selectAll()
  160. self.app.ui.notebook.setTabText(2, _("Drilling Tool"))
  161. def connect_signals_at_init(self):
  162. # #############################################################################
  163. # ############################ SIGNALS ########################################
  164. # #############################################################################
  165. self.t_ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
  166. self.t_ui.generate_cnc_button.clicked.connect(self.on_cnc_button_click)
  167. self.t_ui.tools_table.drag_drop_sig.connect(self.rebuild_ui)
  168. # Exclusion areas signals
  169. self.t_ui.exclusion_table.horizontalHeader().sectionClicked.connect(self.exclusion_table_toggle_all)
  170. self.t_ui.exclusion_table.lost_focus.connect(self.clear_selection)
  171. self.t_ui.exclusion_table.itemClicked.connect(self.draw_sel_shape)
  172. self.t_ui.add_area_button.clicked.connect(self.on_add_area_click)
  173. self.t_ui.delete_area_button.clicked.connect(self.on_clear_area_click)
  174. self.t_ui.delete_sel_area_button.clicked.connect(self.on_delete_sel_areas)
  175. self.t_ui.strategy_radio.activated_custom.connect(self.on_strategy)
  176. self.t_ui.pp_excellon_name_cb.activated.connect(self.on_pp_changed)
  177. self.t_ui.reset_button.clicked.connect(self.set_tool_ui)
  178. # Cleanup on Graceful exit (CTRL+ALT+X combo key)
  179. self.app.cleanup.connect(self.set_tool_ui)
  180. def set_tool_ui(self):
  181. self.units = self.app.defaults['units'].upper()
  182. self.old_tool_dia = self.app.defaults["tools_iso_newdia"]
  183. # try to select in the Excellon combobox the active object
  184. try:
  185. selected_obj = self.app.collection.get_active()
  186. if selected_obj.kind == 'excellon':
  187. current_name = selected_obj.options['name']
  188. self.t_ui.object_combo.set_value(current_name)
  189. except Exception:
  190. pass
  191. # reset the Excellon preprocessor combo
  192. self.t_ui.pp_excellon_name_cb.clear()
  193. # populate Excellon preprocessor combobox list
  194. for name in list(self.app.preprocessors.keys()):
  195. # the HPGL preprocessor is only for Geometry not for Excellon job therefore don't add it
  196. if name == 'hpgl':
  197. continue
  198. self.t_ui.pp_excellon_name_cb.addItem(name)
  199. # add tooltips
  200. for it in range(self.t_ui.pp_excellon_name_cb.count()):
  201. self.t_ui.pp_excellon_name_cb.setItemData(
  202. it, self.t_ui.pp_excellon_name_cb.itemText(it), QtCore.Qt.ToolTipRole)
  203. # update the changes in UI depending on the selected preprocessor in Preferences
  204. # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
  205. # self.t_ui.pp_excellon_name_cb combobox
  206. self.on_pp_changed()
  207. app_mode = self.app.defaults["global_app_level"]
  208. # Show/Hide Advanced Options
  209. if app_mode == 'b':
  210. self.t_ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
  211. self.t_ui.estartz_label.hide()
  212. self.t_ui.estartz_entry.hide()
  213. self.t_ui.feedrate_rapid_label.hide()
  214. self.t_ui.feedrate_rapid_entry.hide()
  215. self.t_ui.pdepth_label.hide()
  216. self.t_ui.pdepth_entry.hide()
  217. self.t_ui.feedrate_probe_label.hide()
  218. self.t_ui.feedrate_probe_entry.hide()
  219. else:
  220. self.t_ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
  221. self.t_ui.estartz_label.show()
  222. self.t_ui.estartz_entry.show()
  223. self.t_ui.feedrate_rapid_label.show()
  224. self.t_ui.feedrate_rapid_entry.show()
  225. self.t_ui.pdepth_label.show()
  226. self.t_ui.pdepth_entry.show()
  227. self.t_ui.feedrate_probe_label.show()
  228. self.t_ui.feedrate_probe_entry.show()
  229. self.t_ui.tools_frame.show()
  230. self.t_ui.order_radio.set_value(self.app.defaults["excellon_tool_order"])
  231. loaded_obj = self.app.collection.get_by_name(self.t_ui.object_combo.get_value())
  232. if loaded_obj:
  233. outname = loaded_obj.options['name']
  234. else:
  235. outname = ''
  236. # init the working variables
  237. self.default_data.clear()
  238. self.default_data = {
  239. "name": outname + '_drill',
  240. "plot": self.app.defaults["excellon_plot"],
  241. "solid": self.app.defaults["excellon_solid"],
  242. "multicolored": self.app.defaults["excellon_multicolored"],
  243. "merge_fuse_tools": self.app.defaults["excellon_merge_fuse_tools"],
  244. "format_upper_in": self.app.defaults["excellon_format_upper_in"],
  245. "format_lower_in": self.app.defaults["excellon_format_lower_in"],
  246. "format_upper_mm": self.app.defaults["excellon_format_upper_mm"],
  247. "lower_mm": self.app.defaults["excellon_format_lower_mm"],
  248. "zeros": self.app.defaults["excellon_zeros"],
  249. "excellon_units": self.app.defaults["excellon_units"],
  250. "excellon_update": self.app.defaults["excellon_update"],
  251. "excellon_optimization_type": self.app.defaults["excellon_optimization_type"],
  252. "excellon_search_time": self.app.defaults["excellon_search_time"],
  253. "excellon_plot_fill": self.app.defaults["excellon_plot_fill"],
  254. "excellon_plot_line": self.app.defaults["excellon_plot_line"],
  255. # Excellon Options
  256. "excellon_tool_order": self.app.defaults["excellon_tool_order"],
  257. "cutz": self.app.defaults["excellon_cutz"],
  258. "multidepth": self.app.defaults["excellon_multidepth"],
  259. "depthperpass": self.app.defaults["excellon_depthperpass"],
  260. "travelz": self.app.defaults["excellon_travelz"],
  261. "endz": self.app.defaults["excellon_endz"],
  262. "endxy": self.app.defaults["excellon_endxy"],
  263. "feedrate_z": self.app.defaults["excellon_feedrate_z"],
  264. "spindlespeed": self.app.defaults["excellon_spindlespeed"],
  265. "dwell": self.app.defaults["excellon_dwell"],
  266. "dwelltime": self.app.defaults["excellon_dwelltime"],
  267. "toolchange": self.app.defaults["excellon_toolchange"],
  268. "toolchangez": self.app.defaults["excellon_toolchangez"],
  269. "ppname_e": self.app.defaults["excellon_ppname_e"],
  270. "tooldia": self.app.defaults["excellon_tooldia"],
  271. "slot_tooldia": self.app.defaults["excellon_slot_tooldia"],
  272. "gcode_type": self.app.defaults["excellon_gcode_type"],
  273. "excellon_area_exclusion": self.app.defaults["excellon_area_exclusion"],
  274. "excellon_area_shape": self.app.defaults["excellon_area_shape"],
  275. "excellon_area_strategy": self.app.defaults["excellon_area_strategy"],
  276. "excellon_area_overz": self.app.defaults["excellon_area_overz"],
  277. # Excellon Advanced Options
  278. "offset": self.app.defaults["excellon_offset"],
  279. "toolchangexy": self.app.defaults["excellon_toolchangexy"],
  280. "startz": self.app.defaults["excellon_startz"],
  281. "feedrate_rapid": self.app.defaults["excellon_feedrate_rapid"],
  282. "z_pdepth": self.app.defaults["excellon_z_pdepth"],
  283. "feedrate_probe": self.app.defaults["excellon_feedrate_probe"],
  284. "spindledir": self.app.defaults["excellon_spindledir"],
  285. "f_plunge": self.app.defaults["excellon_f_plunge"],
  286. "f_retract": self.app.defaults["excellon_f_retract"],
  287. # Drill Slots
  288. "drill_slots": self.app.defaults["excellon_drill_slots"],
  289. "drill_overlap": self.app.defaults["excellon_drill_overlap"],
  290. "last_drill": self.app.defaults["excellon_last_drill"],
  291. "gcode": '',
  292. "gcode_parsed": '',
  293. "geometry": [],
  294. }
  295. # fill in self.default_data values from self.options
  296. for opt_key, opt_val in self.app.options.items():
  297. if opt_key.find('excellon_') == 0:
  298. self.default_data[opt_key] = deepcopy(opt_val)
  299. self.first_click = False
  300. self.cursor_pos = None
  301. self.mouse_is_dragging = False
  302. self.units = self.app.defaults['units'].upper()
  303. # ########################################
  304. # #######3 TEMP SETTINGS #################
  305. # ########################################
  306. self.t_ui.tools_table.setRowCount(2)
  307. self.t_ui.tools_table.setMinimumHeight(self.t_ui.tools_table.getHeight())
  308. self.t_ui.tools_table.setMaximumHeight(self.t_ui.tools_table.getHeight())
  309. # make sure to update the UI on init
  310. try:
  311. self.excellon_tools = self.excellon_obj.tools
  312. except AttributeError:
  313. # no object loaded
  314. pass
  315. self.build_tool_ui()
  316. # ########################################
  317. # ########################################
  318. # ####### Fill in the parameters #########
  319. # ########################################
  320. # ########################################
  321. self.t_ui.cutz_entry.set_value(self.app.defaults["excellon_cutz"])
  322. self.t_ui.mpass_cb.set_value(self.app.defaults["excellon_multidepth"])
  323. self.t_ui.maxdepth_entry.set_value(self.app.defaults["excellon_depthperpass"])
  324. self.t_ui.travelz_entry.set_value(self.app.defaults["excellon_travelz"])
  325. self.t_ui.feedrate_z_entry.set_value(self.app.defaults["excellon_feedrate_z"])
  326. self.t_ui.feedrate_rapid_entry.set_value(self.app.defaults["excellon_feedrate_rapid"])
  327. self.t_ui.spindlespeed_entry.set_value(self.app.defaults["excellon_spindlespeed"])
  328. self.t_ui.dwell_cb.set_value(self.app.defaults["excellon_dwell"])
  329. self.t_ui.dwelltime_entry.set_value(self.app.defaults["excellon_dwelltime"])
  330. self.t_ui.offset_entry.set_value(self.app.defaults["excellon_offset"])
  331. self.t_ui.toolchange_cb.set_value(self.app.defaults["excellon_toolchange"])
  332. self.t_ui.toolchangez_entry.set_value(self.app.defaults["excellon_toolchangez"])
  333. self.t_ui.estartz_entry.set_value(self.app.defaults["excellon_startz"])
  334. self.t_ui.endz_entry.set_value(self.app.defaults["excellon_endz"])
  335. self.t_ui.endxy_entry.set_value(self.app.defaults["excellon_endxy"])
  336. self.t_ui.pdepth_entry.set_value(self.app.defaults["excellon_z_pdepth"])
  337. self.t_ui.feedrate_probe_entry.set_value(self.app.defaults["excellon_feedrate_probe"])
  338. self.t_ui.exclusion_cb.set_value(self.app.defaults["excellon_area_exclusion"])
  339. self.t_ui.strategy_radio.set_value(self.app.defaults["excellon_area_strategy"])
  340. self.t_ui.over_z_entry.set_value(self.app.defaults["excellon_area_overz"])
  341. self.t_ui.area_shape_radio.set_value(self.app.defaults["excellon_area_shape"])
  342. # Drill slots - part of the Advanced Excellon params
  343. self.t_ui.drill_slots_cb.set_value(self.app.defaults["excellon_drill_slots"])
  344. self.t_ui.drill_overlap_entry.set_value(self.app.defaults["excellon_drill_overlap"])
  345. self.t_ui.last_drill_cb.set_value(self.app.defaults["excellon_last_drill"])
  346. # if the app mode is Basic then disable this feature
  347. if app_mode == 'b':
  348. self.t_ui.drill_slots_cb.set_value(False)
  349. self.t_ui.drill_slots_cb.hide()
  350. self.t_ui.drill_overlap_label.hide()
  351. self.t_ui.drill_overlap_entry.hide()
  352. self.t_ui.last_drill_cb.hide()
  353. else:
  354. self.t_ui.drill_slots_cb.show()
  355. self.t_ui.drill_overlap_label.show()
  356. self.t_ui.drill_overlap_entry.show()
  357. self.t_ui.last_drill_cb.show()
  358. try:
  359. self.t_ui.object_combo.currentTextChanged.disconnect()
  360. except (AttributeError, TypeError):
  361. pass
  362. self.t_ui.object_combo.currentTextChanged.connect(self.on_object_changed)
  363. def rebuild_ui(self):
  364. # read the table tools uid
  365. current_uid_list = []
  366. for row in range(self.t_ui.tools_table.rowCount()):
  367. try:
  368. uid = int(self.t_ui.tools_table.item(row, 3).text())
  369. current_uid_list.append(uid)
  370. except AttributeError:
  371. continue
  372. new_tools = {}
  373. new_uid = 1
  374. for current_uid in current_uid_list:
  375. new_tools[new_uid] = deepcopy(self.excellon_tools[current_uid])
  376. new_uid += 1
  377. self.excellon_tools = new_tools
  378. # the tools table changed therefore we need to rebuild it
  379. QtCore.QTimer.singleShot(20, self.build_tool_ui)
  380. def build_tool_ui(self):
  381. log.debug("ToolDrilling.build_tool_ui()")
  382. self.ui_disconnect()
  383. # order the tools by tool diameter if it's the case
  384. sorted_tools = []
  385. for k, v in self.excellon_tools.items():
  386. sorted_tools.append(float('%.*f' % (self.decimals, float(v['tooldia']))))
  387. order = self.t_ui.order_radio.get_value()
  388. if order == 'fwd':
  389. sorted_tools.sort(reverse=False)
  390. elif order == 'rev':
  391. sorted_tools.sort(reverse=True)
  392. else:
  393. pass
  394. # remake the excellon_tools dict in the order above
  395. new_id = 1
  396. new_tools = {}
  397. for tooldia in sorted_tools:
  398. for old_tool in self.excellon_tools:
  399. if float('%.*f' % (self.decimals, float(self.excellon_tools[old_tool]['tooldia']))) == tooldia:
  400. new_tools[new_id] = deepcopy(self.excellon_tools[old_tool])
  401. new_id += 1
  402. self.excellon_tools = new_tools
  403. if self.excellon_obj and self.excellon_tools:
  404. self.t_ui.exc_param_frame.setDisabled(False)
  405. tools = [k for k in self.excellon_tools]
  406. else:
  407. self.t_ui.exc_param_frame.setDisabled(True)
  408. self.t_ui.tools_table.setRowCount(2)
  409. tools = []
  410. n = len(tools)
  411. # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
  412. self.t_ui.tools_table.setRowCount(n + 2)
  413. self.tool_row = 0
  414. tot_drill_cnt = 0
  415. tot_slot_cnt = 0
  416. for tool_no in tools:
  417. # Find no of drills for the current tool
  418. try:
  419. drill_cnt = len(self.excellon_tools[tool_no]["drills"]) # variable to store the nr of drills per tool
  420. except KeyError:
  421. drill_cnt = 0
  422. tot_drill_cnt += drill_cnt
  423. # Find no of slots for the current tool
  424. try:
  425. slot_cnt = len(self.excellon_tools[tool_no]["slots"]) # variable to store the nr of slots per tool
  426. except KeyError:
  427. slot_cnt = 0
  428. tot_slot_cnt += slot_cnt
  429. # Tool name/id
  430. exc_id_item = QtWidgets.QTableWidgetItem('%d' % int(tool_no))
  431. exc_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled)
  432. self.t_ui.tools_table.setItem(self.tool_row, 0, exc_id_item)
  433. # Tool Diameter
  434. dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.excellon_tools[tool_no]['tooldia']))
  435. dia_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled)
  436. self.t_ui.tools_table.setItem(self.tool_row, 1, dia_item)
  437. # Number of drills per tool
  438. drill_count_item = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
  439. drill_count_item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled)
  440. self.t_ui.tools_table.setItem(self.tool_row, 2, drill_count_item)
  441. # Tool unique ID
  442. tool_uid_item = QtWidgets.QTableWidgetItem(str(int(tool_no)))
  443. # ## REMEMBER: THIS COLUMN IS HIDDEN in UI
  444. self.t_ui.tools_table.setItem(self.tool_row, 3, tool_uid_item)
  445. # Number of slots per tool
  446. # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
  447. slot_count_str = '%d' % slot_cnt if slot_cnt > 0 else ''
  448. slot_count_item = QtWidgets.QTableWidgetItem(slot_count_str)
  449. slot_count_item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled)
  450. self.t_ui.tools_table.setItem(self.tool_row, 4, slot_count_item)
  451. self.tool_row += 1
  452. # add a last row with the Total number of drills
  453. empty_1 = QtWidgets.QTableWidgetItem('')
  454. empty_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  455. empty_1_1 = QtWidgets.QTableWidgetItem('')
  456. empty_1_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  457. label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
  458. label_tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
  459. tot_drill_count = QtWidgets.QTableWidgetItem('%d' % tot_drill_cnt)
  460. tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
  461. self.t_ui.tools_table.setItem(self.tool_row, 0, empty_1)
  462. self.t_ui.tools_table.setItem(self.tool_row, 1, label_tot_drill_count)
  463. self.t_ui.tools_table.setItem(self.tool_row, 2, tot_drill_count) # Total number of drills
  464. self.t_ui.tools_table.setItem(self.tool_row, 4, empty_1_1)
  465. font = QtGui.QFont()
  466. font.setBold(True)
  467. font.setWeight(75)
  468. for k in [1, 2]:
  469. self.t_ui.tools_table.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
  470. self.t_ui.tools_table.item(self.tool_row, k).setFont(font)
  471. self.tool_row += 1
  472. # add a last row with the Total number of slots
  473. empty_2 = QtWidgets.QTableWidgetItem('')
  474. empty_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  475. empty_2_1 = QtWidgets.QTableWidgetItem('')
  476. empty_2_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  477. label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
  478. tot_slot_count = QtWidgets.QTableWidgetItem('%d' % tot_slot_cnt)
  479. label_tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
  480. tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
  481. self.t_ui.tools_table.setItem(self.tool_row, 0, empty_2)
  482. self.t_ui.tools_table.setItem(self.tool_row, 1, label_tot_slot_count)
  483. self.t_ui.tools_table.setItem(self.tool_row, 2, empty_2_1)
  484. self.t_ui.tools_table.setItem(self.tool_row, 4, tot_slot_count) # Total number of slots
  485. for kl in [1, 2, 4]:
  486. self.t_ui.tools_table.item(self.tool_row, kl).setFont(font)
  487. self.t_ui.tools_table.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
  488. # make the diameter column editable
  489. # for row in range(self.t_ui.tools_table.rowCount() - 2):
  490. # self.t_ui.tools_table.item(row, 1).setFlags(
  491. # QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  492. self.t_ui.tools_table.resizeColumnsToContents()
  493. self.t_ui.tools_table.resizeRowsToContents()
  494. vertical_header = self.t_ui.tools_table.verticalHeader()
  495. vertical_header.hide()
  496. self.t_ui.tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  497. horizontal_header = self.t_ui.tools_table.horizontalHeader()
  498. self.t_ui.tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  499. horizontal_header.setMinimumSectionSize(10)
  500. horizontal_header.setDefaultSectionSize(70)
  501. horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
  502. horizontal_header.resizeSection(0, 20)
  503. horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
  504. horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
  505. horizontal_header.setSectionResizeMode(4, QtWidgets.QHeaderView.ResizeToContents)
  506. self.t_ui.tools_table.setSortingEnabled(False)
  507. self.t_ui.tools_table.setMinimumHeight(self.t_ui.tools_table.getHeight())
  508. self.t_ui.tools_table.setMaximumHeight(self.t_ui.tools_table.getHeight())
  509. # all the tools are selected by default
  510. self.t_ui.tools_table.selectAll()
  511. # Build Exclusion Areas section
  512. e_len = len(self.app.exc_areas.exclusion_areas_storage)
  513. self.t_ui.exclusion_table.setRowCount(e_len)
  514. area_id = 0
  515. for area in range(e_len):
  516. area_id += 1
  517. area_dict = self.app.exc_areas.exclusion_areas_storage[area]
  518. area_id_item = QtWidgets.QTableWidgetItem('%d' % int(area_id))
  519. area_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  520. self.t_ui.exclusion_table.setItem(area, 0, area_id_item) # Area id
  521. object_item = QtWidgets.QTableWidgetItem('%s' % area_dict["obj_type"])
  522. object_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  523. self.t_ui.exclusion_table.setItem(area, 1, object_item) # Origin Object
  524. strategy_item = QtWidgets.QTableWidgetItem('%s' % area_dict["strategy"])
  525. strategy_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  526. self.t_ui.exclusion_table.setItem(area, 2, strategy_item) # Strategy
  527. overz_item = QtWidgets.QTableWidgetItem('%s' % area_dict["overz"])
  528. overz_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  529. self.t_ui.exclusion_table.setItem(area, 3, overz_item) # Over Z
  530. self.t_ui.exclusion_table.resizeColumnsToContents()
  531. self.t_ui.exclusion_table.resizeRowsToContents()
  532. area_vheader = self.t_ui.exclusion_table.verticalHeader()
  533. area_vheader.hide()
  534. self.t_ui.exclusion_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  535. area_hheader = self.t_ui.exclusion_table.horizontalHeader()
  536. area_hheader.setMinimumSectionSize(10)
  537. area_hheader.setDefaultSectionSize(70)
  538. area_hheader.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
  539. area_hheader.resizeSection(0, 20)
  540. area_hheader.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
  541. area_hheader.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
  542. area_hheader.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
  543. # area_hheader.setStretchLastSection(True)
  544. self.t_ui.exclusion_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
  545. self.t_ui.exclusion_table.setColumnWidth(0, 20)
  546. self.t_ui.exclusion_table.setMinimumHeight(self.t_ui.exclusion_table.getHeight())
  547. self.t_ui.exclusion_table.setMaximumHeight(self.t_ui.exclusion_table.getHeight())
  548. self.ui_connect()
  549. # set the text on tool_data_label after loading the object
  550. sel_rows = set()
  551. sel_items = self.t_ui.tools_table.selectedItems()
  552. for it in sel_items:
  553. sel_rows.add(it.row())
  554. if len(sel_rows) > 1:
  555. self.t_ui.tool_data_label.setText(
  556. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  557. )
  558. elif len(sel_rows) == 1:
  559. # update the QLabel that shows for which Tool we have the parameters in the UI form
  560. toolnr = int(self.t_ui.tools_table.item(list(sel_rows)[0], 0).text())
  561. self.t_ui.tool_data_label.setText(
  562. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), toolnr)
  563. )
  564. def on_object_changed(self):
  565. log.debug("ToolDrilling.on_object_changed()")
  566. # updated units
  567. self.units = self.app.defaults['units'].upper()
  568. # load the Excellon object
  569. self.obj_name = self.t_ui.object_combo.currentText()
  570. # Get source object.
  571. try:
  572. self.excellon_obj = self.app.collection.get_by_name(self.obj_name)
  573. except Exception:
  574. self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), str(self.obj_name)))
  575. return
  576. if self.excellon_obj is None:
  577. self.excellon_tools = {}
  578. self.t_ui.exc_param_frame.setDisabled(True)
  579. self.set_tool_ui()
  580. else:
  581. self.excellon_tools = self.excellon_obj.tools
  582. self.app.collection.set_active(self.obj_name)
  583. self.t_ui.exc_param_frame.setDisabled(False)
  584. self.excellon_tools = self.excellon_obj.tools
  585. self.build_tool_ui()
  586. sel_rows = set()
  587. table_items = self.t_ui.tools_table.selectedItems()
  588. if table_items:
  589. for it in table_items:
  590. sel_rows.add(it.row())
  591. if not sel_rows or len(sel_rows) == 0:
  592. self.t_ui.generate_cnc_button.setDisabled(True)
  593. self.t_ui.tool_data_label.setText(
  594. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
  595. )
  596. else:
  597. self.t_ui.generate_cnc_button.setDisabled(False)
  598. def ui_connect(self):
  599. # Area Exception - exclusion shape added signal
  600. # first disconnect it from any other object
  601. try:
  602. self.app.exc_areas.e_shape_modified.disconnect()
  603. except (TypeError, AttributeError):
  604. pass
  605. # then connect it to the current build_tool_ui() method
  606. self.app.exc_areas.e_shape_modified.connect(self.update_exclusion_table)
  607. # rows selected
  608. self.t_ui.tools_table.clicked.connect(self.on_row_selection_change)
  609. self.t_ui.tools_table.horizontalHeader().sectionClicked.connect(self.on_toggle_all_rows)
  610. # Tool Parameters
  611. for opt in self.form_fields:
  612. current_widget = self.form_fields[opt]
  613. if isinstance(current_widget, FCCheckBox):
  614. current_widget.stateChanged.connect(self.form_to_storage)
  615. if isinstance(current_widget, RadioSet):
  616. current_widget.activated_custom.connect(self.form_to_storage)
  617. elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
  618. current_widget.returnPressed.connect(self.form_to_storage)
  619. elif isinstance(current_widget, FCComboBox):
  620. current_widget.currentIndexChanged.connect(self.form_to_storage)
  621. self.t_ui.order_radio.activated_custom[str].connect(self.on_order_changed)
  622. def ui_disconnect(self):
  623. # rows selected
  624. try:
  625. self.t_ui.tools_table.clicked.disconnect(self.on_row_selection_change)
  626. except (TypeError, AttributeError):
  627. pass
  628. try:
  629. self.t_ui.tools_table.horizontalHeader().sectionClicked.disconnect(self.on_toggle_all_rows)
  630. except (TypeError, AttributeError):
  631. pass
  632. # tool table widgets
  633. for row in range(self.t_ui.tools_table.rowCount()):
  634. try:
  635. self.t_ui.tools_table.cellWidget(row, 2).currentIndexChanged.disconnect()
  636. except (TypeError, AttributeError):
  637. pass
  638. # Tool Parameters
  639. for opt in self.form_fields:
  640. current_widget = self.form_fields[opt]
  641. if isinstance(current_widget, FCCheckBox):
  642. try:
  643. current_widget.stateChanged.disconnect(self.form_to_storage)
  644. except (TypeError, ValueError):
  645. pass
  646. if isinstance(current_widget, RadioSet):
  647. try:
  648. current_widget.activated_custom.disconnect(self.form_to_storage)
  649. except (TypeError, ValueError):
  650. pass
  651. elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
  652. try:
  653. current_widget.returnPressed.disconnect(self.form_to_storage)
  654. except (TypeError, ValueError):
  655. pass
  656. elif isinstance(current_widget, FCComboBox):
  657. try:
  658. current_widget.currentIndexChanged.disconnect(self.form_to_storage)
  659. except (TypeError, ValueError):
  660. pass
  661. try:
  662. self.t_ui.order_radio.activated_custom[str].disconnect()
  663. except (TypeError, ValueError):
  664. pass
  665. def on_toggle_all_rows(self):
  666. """
  667. will toggle the selection of all rows in Tools table
  668. :return:
  669. """
  670. sel_model = self.t_ui.tools_table.selectionModel()
  671. sel_indexes = sel_model.selectedIndexes()
  672. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  673. sel_rows = set()
  674. for idx in sel_indexes:
  675. sel_rows.add(idx.row())
  676. if len(sel_rows) == self.t_ui.tools_table.rowCount():
  677. self.t_ui.tools_table.clearSelection()
  678. self.t_ui.exc_param_frame.setDisabled(True)
  679. else:
  680. self.t_ui.tools_table.selectAll()
  681. self.t_ui.exc_param_frame.setDisabled(False)
  682. self.update_ui()
  683. def on_row_selection_change(self):
  684. self.update_ui()
  685. def update_ui(self):
  686. self.blockSignals(True)
  687. sel_rows = set()
  688. table_items = self.t_ui.tools_table.selectedItems()
  689. if table_items:
  690. for it in table_items:
  691. sel_rows.add(it.row())
  692. # sel_rows = sorted(set(index.row() for index in self.t_ui.tools_table.selectedIndexes()))
  693. if not sel_rows or len(sel_rows) == 0:
  694. self.t_ui.generate_cnc_button.setDisabled(True)
  695. self.t_ui.exc_param_frame.setDisabled(True)
  696. self.t_ui.tool_data_label.setText(
  697. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
  698. )
  699. self.blockSignals(False)
  700. return
  701. else:
  702. self.t_ui.generate_cnc_button.setDisabled(False)
  703. self.t_ui.exc_param_frame.setDisabled(False)
  704. if len(sel_rows) == 1:
  705. # update the QLabel that shows for which Tool we have the parameters in the UI form
  706. tooluid = int(self.t_ui.tools_table.item(list(sel_rows)[0], 0).text())
  707. self.t_ui.tool_data_label.setText(
  708. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
  709. )
  710. else:
  711. self.t_ui.tool_data_label.setText(
  712. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  713. )
  714. for c_row in sel_rows:
  715. # populate the form with the data from the tool associated with the row parameter
  716. try:
  717. item = self.t_ui.tools_table.item(c_row, 3)
  718. if type(item) is not None:
  719. tooluid = int(item.text())
  720. self.storage_to_form(self.excellon_tools[tooluid]['data'])
  721. else:
  722. self.blockSignals(False)
  723. return
  724. except Exception as e:
  725. log.debug("Tool missing. Add a tool in the Tool Table. %s" % str(e))
  726. self.blockSignals(False)
  727. return
  728. self.blockSignals(False)
  729. def storage_to_form(self, dict_storage):
  730. """
  731. Will update the GUI with data from the "storage" in this case the dict self.tools
  732. :param dict_storage: A dictionary holding the data relevant for gnerating Gcode from Excellon
  733. :type dict_storage: dict
  734. :return: None
  735. :rtype:
  736. """
  737. for form_key in self.form_fields:
  738. for storage_key in dict_storage:
  739. if form_key == storage_key and form_key not in \
  740. ["toolchange", "toolchangez", "startz", "endz", "ppname_e", "ppname_g"]:
  741. try:
  742. self.form_fields[form_key].set_value(dict_storage[form_key])
  743. except Exception as e:
  744. log.debug("ToolDrilling.storage_to_form() --> %s" % str(e))
  745. pass
  746. def form_to_storage(self):
  747. """
  748. Will update the 'storage' attribute which is the dict self.tools with data collected from GUI
  749. :return: None
  750. :rtype:
  751. """
  752. if self.t_ui.tools_table.rowCount() == 2:
  753. # there is no tool in tool table so we can't save the GUI elements values to storage
  754. # Excellon Tool Table has 2 rows by default
  755. return
  756. self.blockSignals(True)
  757. widget_changed = self.sender()
  758. wdg_objname = widget_changed.objectName()
  759. option_changed = self.name2option[wdg_objname]
  760. # row = self.t_ui.tools_table.currentRow()
  761. rows = sorted(list(set(index.row() for index in self.t_ui.tools_table.selectedIndexes())))
  762. for row in rows:
  763. if row < 0:
  764. row = 0
  765. tooluid_item = int(self.t_ui.tools_table.item(row, 3).text())
  766. for tooluid_key, tooluid_val in self.excellon_tools.items():
  767. if int(tooluid_key) == tooluid_item:
  768. new_option_value = self.form_fields[option_changed].get_value()
  769. if option_changed in tooluid_val:
  770. tooluid_val[option_changed] = new_option_value
  771. if option_changed in tooluid_val['data']:
  772. tooluid_val['data'][option_changed] = new_option_value
  773. self.blockSignals(False)
  774. def get_selected_tools_list(self):
  775. """
  776. Returns the keys to the self.tools dictionary corresponding
  777. to the selections on the tool list in the appGUI.
  778. :return: List of tools.
  779. :rtype: list
  780. """
  781. return [str(x.text()) for x in self.t_ui.tools_table.selectedItems()]
  782. def get_selected_tools_table_items(self):
  783. """
  784. Returns a list of lists, each list in the list is made out of row elements
  785. :return: List of table_tools items.
  786. :rtype: list
  787. """
  788. table_tools_items = []
  789. rows = set()
  790. for x in self.t_ui.tools_table.selectedItems():
  791. rows.add(x.row())
  792. for row in rows:
  793. txt = ''
  794. elem = []
  795. for column in range(self.t_ui.tools_table.columnCount()):
  796. if column == 3:
  797. # disregard this column since it's the toolID
  798. continue
  799. try:
  800. txt = self.t_ui.tools_table.item(row, column).text()
  801. except AttributeError:
  802. try:
  803. txt = self.t_ui.tools_table.cellWidget(row, column).currentText()
  804. except AttributeError:
  805. pass
  806. elem.append(txt)
  807. table_tools_items.append(deepcopy(elem))
  808. # table_tools_items.append([self.t_ui.tools_table.item(x.row(), column).text()
  809. # for column in range(0, self.t_ui.tools_table.columnCount() - 1)])
  810. for item in table_tools_items:
  811. item[0] = str(item[0])
  812. return table_tools_items
  813. def on_apply_param_to_all_clicked(self):
  814. if self.t_ui.tools_table.rowCount() == 0:
  815. # there is no tool in tool table so we can't save the GUI elements values to storage
  816. log.debug("ToolDrilling.on_apply_param_to_all_clicked() --> no tool in Tools Table, aborting.")
  817. return
  818. self.blockSignals(True)
  819. row = self.t_ui.tools_table.currentRow()
  820. if row < 0:
  821. row = 0
  822. tooluid_item = int(self.t_ui.tools_table.item(row, 3).text())
  823. temp_tool_data = {}
  824. for tooluid_key, tooluid_val in self.excellon_tools.items():
  825. if int(tooluid_key) == tooluid_item:
  826. # this will hold the 'data' key of the self.tools[tool] dictionary that corresponds to
  827. # the current row in the tool table
  828. temp_tool_data = tooluid_val['data']
  829. break
  830. for tooluid_key, tooluid_val in self.excellon_tools.items():
  831. tooluid_val['data'] = deepcopy(temp_tool_data)
  832. self.app.inform.emit('[success] %s' % _("Current Tool parameters were applied to all tools."))
  833. self.blockSignals(False)
  834. def on_order_changed(self, order):
  835. if order != 'no':
  836. self.build_tool_ui()
  837. def on_tooltable_cellwidget_change(self):
  838. cw = self.sender()
  839. assert isinstance(cw, QtWidgets.QComboBox), \
  840. "Expected a QtWidgets.QComboBox, got %s" % isinstance(cw, QtWidgets.QComboBox)
  841. cw_index = self.t_ui.tools_table.indexAt(cw.pos())
  842. cw_row = cw_index.row()
  843. cw_col = cw_index.column()
  844. current_uid = int(self.t_ui.tools_table.item(cw_row, 3).text())
  845. # if the sender is in the column with index 2 then we update the tool_type key
  846. if cw_col == 2:
  847. tt = cw.currentText()
  848. typ = 'Iso' if tt == 'V' else "Rough"
  849. self.excellon_tools[current_uid].update({
  850. 'type': typ,
  851. 'tool_type': tt,
  852. })
  853. def generate_milling_drills(self, tools=None, outname=None, tooldia=None, plot=False, use_thread=False):
  854. """
  855. Will generate an Geometry Object allowing to cut a drill hole instead of drilling it.
  856. Note: This method is a good template for generic operations as
  857. it takes it's options from parameters or otherwise from the
  858. object's options and returns a (success, msg) tuple as feedback
  859. for shell operations.
  860. :param tools: A list of tools where the drills are to be milled or a string: "all"
  861. :type tools:
  862. :param outname: the name of the resulting Geometry object
  863. :type outname: str
  864. :param tooldia: the tool diameter to be used in creation of the milling path (Geometry Object)
  865. :type tooldia: float
  866. :param plot: if to plot the resulting object
  867. :type plot: bool
  868. :param use_thread: if to use threading for creation of the Geometry object
  869. :type use_thread: bool
  870. :return: Success/failure condition tuple (bool, str).
  871. :rtype: tuple
  872. """
  873. # Get the tools from the list. These are keys
  874. # to self.tools
  875. if tools is None:
  876. tools = self.get_selected_tools_list()
  877. if outname is None:
  878. outname = self.options["name"] + "_mill"
  879. if tooldia is None:
  880. tooldia = float(self.options["tooldia"])
  881. # Sort tools by diameter. items() -> [('name', diameter), ...]
  882. # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
  883. sort = []
  884. for k, v in self.tools.items():
  885. sort.append((k, v.get('tooldia')))
  886. sorted_tools = sorted(sort, key=lambda t1: t1[1])
  887. if tools == "all":
  888. tools = [i[0] for i in sorted_tools] # List if ordered tool names.
  889. log.debug("Tools 'all' and sorted are: %s" % str(tools))
  890. if len(tools) == 0:
  891. self.app.inform.emit('[ERROR_NOTCL] %s' %
  892. _("Please select one or more tools from the list and try again."))
  893. return False, "Error: No tools."
  894. for tool in tools:
  895. if tooldia > self.tools[tool]["C"]:
  896. self.app.inform.emit(
  897. '[ERROR_NOTCL] %s %s: %s' % (
  898. _("Milling tool for DRILLS is larger than hole size. Cancelled."),
  899. _("Tool"),
  900. str(tool)
  901. )
  902. )
  903. return False, "Error: Milling tool is larger than hole."
  904. def geo_init(geo_obj, app_obj):
  905. """
  906. :param geo_obj: New object
  907. :type geo_obj: GeometryObject
  908. :param app_obj: App
  909. :type app_obj: FlatCAMApp.App
  910. :return:
  911. :rtype:
  912. """
  913. assert geo_obj.kind == 'geometry', "Initializer expected a GeometryObject, got %s" % type(geo_obj)
  914. app_obj.inform.emit(_("Generating drills milling geometry..."))
  915. # ## Add properties to the object
  916. # get the tool_table items in a list of row items
  917. tool_table_items = self.get_selected_tools_table_items()
  918. # insert an information only element in the front
  919. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  920. geo_obj.options['Tools_in_use'] = tool_table_items
  921. geo_obj.options['type'] = 'Excellon Geometry'
  922. geo_obj.options["cnctooldia"] = str(tooldia)
  923. geo_obj.options["multidepth"] = self.options["multidepth"]
  924. geo_obj.solid_geometry = []
  925. # in case that the tool used has the same diameter with the hole, and since the maximum resolution
  926. # for FlatCAM is 6 decimals,
  927. # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
  928. for hole in self.drills:
  929. if hole['tool'] in tools:
  930. buffer_value = self.tools[hole['tool']]["C"] / 2 - tooldia / 2
  931. if buffer_value == 0:
  932. geo_obj.solid_geometry.append(
  933. Point(hole['point']).buffer(0.0000001).exterior)
  934. else:
  935. geo_obj.solid_geometry.append(
  936. Point(hole['point']).buffer(buffer_value).exterior)
  937. if use_thread:
  938. def geo_thread(a_obj):
  939. a_obj.app_obj.new_object("geometry", outname, geo_init, plot=plot)
  940. # Create a promise with the new name
  941. self.app.collection.promise(outname)
  942. # Send to worker
  943. self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
  944. else:
  945. self.app.app_obj.new_object("geometry", outname, geo_init, plot=plot)
  946. return True, ""
  947. def generate_milling_slots(self, tools=None, outname=None, tooldia=None, plot=False, use_thread=False):
  948. """
  949. Will generate an Geometry Object allowing to cut/mill a slot hole.
  950. Note: This method is a good template for generic operations as
  951. it takes it's options from parameters or otherwise from the
  952. object's options and returns a (success, msg) tuple as feedback
  953. for shell operations.
  954. :param tools: A list of tools where the drills are to be milled or a string: "all"
  955. :type tools:
  956. :param outname: the name of the resulting Geometry object
  957. :type outname: str
  958. :param tooldia: the tool diameter to be used in creation of the milling path (Geometry Object)
  959. :type tooldia: float
  960. :param plot: if to plot the resulting object
  961. :type plot: bool
  962. :param use_thread: if to use threading for creation of the Geometry object
  963. :type use_thread: bool
  964. :return: Success/failure condition tuple (bool, str).
  965. :rtype: tuple
  966. """
  967. # Get the tools from the list. These are keys
  968. # to self.tools
  969. if tools is None:
  970. tools = self.get_selected_tools_list()
  971. if outname is None:
  972. outname = self.options["name"] + "_mill"
  973. if tooldia is None:
  974. tooldia = float(self.options["slot_tooldia"])
  975. # Sort tools by diameter. items() -> [('name', diameter), ...]
  976. # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
  977. sort = []
  978. for k, v in self.tools.items():
  979. sort.append((k, v.get('tooldia')))
  980. sorted_tools = sorted(sort, key=lambda t1: t1[1])
  981. if tools == "all":
  982. tools = [i[0] for i in sorted_tools] # List if ordered tool names.
  983. log.debug("Tools 'all' and sorted are: %s" % str(tools))
  984. if len(tools) == 0:
  985. self.app.inform.emit('[ERROR_NOTCL] %s' %
  986. _("Please select one or more tools from the list and try again."))
  987. return False, "Error: No tools."
  988. for tool in tools:
  989. # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
  990. adj_toolstable_tooldia = float('%.*f' % (self.decimals, float(tooldia)))
  991. adj_file_tooldia = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
  992. if adj_toolstable_tooldia > adj_file_tooldia + 0.0001:
  993. self.app.inform.emit('[ERROR_NOTCL] %s' %
  994. _("Milling tool for SLOTS is larger than hole size. Cancelled."))
  995. return False, "Error: Milling tool is larger than hole."
  996. def geo_init(geo_obj, app_obj):
  997. assert geo_obj.kind == 'geometry', "Initializer expected a GeometryObject, got %s" % type(geo_obj)
  998. app_obj.inform.emit(_("Generating slot milling geometry..."))
  999. # ## Add properties to the object
  1000. # get the tool_table items in a list of row items
  1001. tool_table_items = self.get_selected_tools_table_items()
  1002. # insert an information only element in the front
  1003. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1004. geo_obj.options['Tools_in_use'] = tool_table_items
  1005. geo_obj.options['type'] = 'Excellon Geometry'
  1006. geo_obj.options["cnctooldia"] = str(tooldia)
  1007. geo_obj.options["multidepth"] = self.options["multidepth"]
  1008. geo_obj.solid_geometry = []
  1009. # in case that the tool used has the same diameter with the hole, and since the maximum resolution
  1010. # for FlatCAM is 6 decimals,
  1011. # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
  1012. for slot in self.slots:
  1013. if slot['tool'] in tools:
  1014. toolstable_tool = float('%.*f' % (self.decimals, float(tooldia)))
  1015. file_tool = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
  1016. # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
  1017. # for the file_tool (tooldia actually)
  1018. buffer_value = float(file_tool / 2) - float(toolstable_tool / 2) + 0.0001
  1019. if buffer_value == 0:
  1020. start = slot['start']
  1021. stop = slot['stop']
  1022. lines_string = LineString([start, stop])
  1023. poly = lines_string.buffer(0.0000001, int(self.geo_steps_per_circle)).exterior
  1024. geo_obj.solid_geometry.append(poly)
  1025. else:
  1026. start = slot['start']
  1027. stop = slot['stop']
  1028. lines_string = LineString([start, stop])
  1029. poly = lines_string.buffer(buffer_value, int(self.geo_steps_per_circle)).exterior
  1030. geo_obj.solid_geometry.append(poly)
  1031. if use_thread:
  1032. def geo_thread(a_obj):
  1033. a_obj.app_obj.new_object("geometry", outname + '_slot', geo_init, plot=plot)
  1034. # Create a promise with the new name
  1035. self.app.collection.promise(outname)
  1036. # Send to worker
  1037. self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
  1038. else:
  1039. self.app.app_obj.new_object("geometry", outname + '_slot', geo_init, plot=plot)
  1040. return True, ""
  1041. def on_pp_changed(self):
  1042. current_pp = self.t_ui.pp_excellon_name_cb.get_value()
  1043. if "toolchange_probe" in current_pp.lower():
  1044. self.t_ui.pdepth_entry.setVisible(True)
  1045. self.t_ui.pdepth_label.show()
  1046. self.t_ui.feedrate_probe_entry.setVisible(True)
  1047. self.t_ui.feedrate_probe_label.show()
  1048. else:
  1049. self.t_ui.pdepth_entry.setVisible(False)
  1050. self.t_ui.pdepth_label.hide()
  1051. self.t_ui.feedrate_probe_entry.setVisible(False)
  1052. self.t_ui.feedrate_probe_label.hide()
  1053. if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
  1054. self.t_ui.feedrate_rapid_label.show()
  1055. self.t_ui.feedrate_rapid_entry.show()
  1056. else:
  1057. self.t_ui.feedrate_rapid_label.hide()
  1058. self.t_ui.feedrate_rapid_entry.hide()
  1059. if 'laser' in current_pp.lower():
  1060. self.t_ui.cutzlabel.hide()
  1061. self.t_ui.cutz_entry.hide()
  1062. try:
  1063. self.t_ui.mpass_cb.hide()
  1064. self.t_ui.maxdepth_entry.hide()
  1065. except AttributeError:
  1066. pass
  1067. if 'marlin' in current_pp.lower():
  1068. self.t_ui.travelzlabel.setText('%s:' % _("Focus Z"))
  1069. self.t_ui.endz_label.show()
  1070. self.t_ui.endz_entry.show()
  1071. else:
  1072. self.t_ui.travelzlabel.hide()
  1073. self.t_ui.travelz_entry.hide()
  1074. self.t_ui.endz_label.hide()
  1075. self.t_ui.endz_entry.hide()
  1076. try:
  1077. self.t_ui.frzlabel.hide()
  1078. self.t_ui.feedrate_z_entry.hide()
  1079. except AttributeError:
  1080. pass
  1081. self.t_ui.dwell_cb.hide()
  1082. self.t_ui.dwelltime_entry.hide()
  1083. self.t_ui.spindle_label.setText('%s:' % _("Laser Power"))
  1084. try:
  1085. self.t_ui.tool_offset_label.hide()
  1086. self.t_ui.offset_entry.hide()
  1087. except AttributeError:
  1088. pass
  1089. else:
  1090. self.t_ui.cutzlabel.show()
  1091. self.t_ui.cutz_entry.show()
  1092. try:
  1093. self.t_ui.mpass_cb.show()
  1094. self.t_ui.maxdepth_entry.show()
  1095. except AttributeError:
  1096. pass
  1097. self.t_ui.travelzlabel.setText('%s:' % _('Travel Z'))
  1098. self.t_ui.travelzlabel.show()
  1099. self.t_ui.travelz_entry.show()
  1100. self.t_ui.endz_label.show()
  1101. self.t_ui.endz_entry.show()
  1102. try:
  1103. self.t_ui.frzlabel.show()
  1104. self.t_ui.feedrate_z_entry.show()
  1105. except AttributeError:
  1106. pass
  1107. self.t_ui.dwell_cb.show()
  1108. self.t_ui.dwelltime_entry.show()
  1109. self.t_ui.spindle_label.setText('%s:' % _('Spindle speed'))
  1110. try:
  1111. # self.t_ui.tool_offset_lbl.show()
  1112. self.t_ui.offset_entry.show()
  1113. except AttributeError:
  1114. pass
  1115. def on_key_press(self, event):
  1116. # modifiers = QtWidgets.QApplication.keyboardModifiers()
  1117. # matplotlib_key_flag = False
  1118. # events out of the self.app.collection view (it's about Project Tab) are of type int
  1119. if type(event) is int:
  1120. key = event
  1121. # events from the GUI are of type QKeyEvent
  1122. elif type(event) == QtGui.QKeyEvent:
  1123. key = event.key()
  1124. elif isinstance(event, mpl_key_event): # MatPlotLib key events are trickier to interpret than the rest
  1125. # matplotlib_key_flag = True
  1126. key = event.key
  1127. key = QtGui.QKeySequence(key)
  1128. # check for modifiers
  1129. key_string = key.toString().lower()
  1130. if '+' in key_string:
  1131. mod, __, key_text = key_string.rpartition('+')
  1132. if mod.lower() == 'ctrl':
  1133. # modifiers = QtCore.Qt.ControlModifier
  1134. pass
  1135. elif mod.lower() == 'alt':
  1136. # modifiers = QtCore.Qt.AltModifier
  1137. pass
  1138. elif mod.lower() == 'shift':
  1139. # modifiers = QtCore.Qt.ShiftModifier
  1140. pass
  1141. else:
  1142. # modifiers = QtCore.Qt.NoModifier
  1143. pass
  1144. key = QtGui.QKeySequence(key_text)
  1145. # events from Vispy are of type KeyEvent
  1146. else:
  1147. key = event.key
  1148. if key == QtCore.Qt.Key_Escape or key == 'Escape':
  1149. self.points = []
  1150. self.poly_drawn = False
  1151. self.delete_moving_selection_shape()
  1152. self.delete_tool_selection_shape()
  1153. def on_add_area_click(self):
  1154. shape_button = self.t_ui.area_shape_radio
  1155. overz_button = self.t_ui.over_z_entry
  1156. strategy_radio = self.t_ui.strategy_radio
  1157. cnc_button = self.t_ui.generate_cnc_button
  1158. solid_geo = self.excellon_obj.solid_geometry
  1159. obj_type = self.excellon_obj.kind
  1160. self.app.exc_areas.on_add_area_click(
  1161. shape_button=shape_button, overz_button=overz_button, cnc_button=cnc_button, strategy_radio=strategy_radio,
  1162. solid_geo=solid_geo, obj_type=obj_type)
  1163. def on_clear_area_click(self):
  1164. if not self.app.exc_areas.exclusion_areas_storage:
  1165. self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. There are no exclusion areas to delete."))
  1166. return
  1167. self.app.exc_areas.on_clear_area_click()
  1168. self.app.exc_areas.e_shape_modified.emit()
  1169. def on_delete_sel_areas(self):
  1170. sel_model = self.t_ui.exclusion_table.selectionModel()
  1171. sel_indexes = sel_model.selectedIndexes()
  1172. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1173. # so the duplicate rows will not be added
  1174. sel_rows = set()
  1175. for idx in sel_indexes:
  1176. sel_rows.add(idx.row())
  1177. if not sel_rows:
  1178. self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. Nothing is selected."))
  1179. return
  1180. self.app.exc_areas.delete_sel_shapes(idxs=list(sel_rows))
  1181. self.app.exc_areas.e_shape_modified.emit()
  1182. def draw_sel_shape(self):
  1183. sel_model = self.t_ui.exclusion_table.selectionModel()
  1184. sel_indexes = sel_model.selectedIndexes()
  1185. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1186. sel_rows = set()
  1187. for idx in sel_indexes:
  1188. sel_rows.add(idx.row())
  1189. self.delete_sel_shape()
  1190. if self.app.is_legacy is False:
  1191. face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.2 * 255)))[2:]
  1192. outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(0.8 * 255)))[2:]
  1193. else:
  1194. face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.4 * 255)))[2:]
  1195. outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(1.0 * 255)))[2:]
  1196. for row in sel_rows:
  1197. sel_rect = self.app.exc_areas.exclusion_areas_storage[row]['shape']
  1198. self.app.move_tool.sel_shapes.add(sel_rect, color=outline, face_color=face, update=True, layer=0,
  1199. tolerance=None)
  1200. if self.app.is_legacy is True:
  1201. self.app.move_tool.sel_shapes.redraw()
  1202. def clear_selection(self):
  1203. self.app.delete_selection_shape()
  1204. # self.t_ui.exclusion_table.clearSelection()
  1205. def delete_sel_shape(self):
  1206. self.app.delete_selection_shape()
  1207. def update_exclusion_table(self):
  1208. self.exclusion_area_cb_is_checked = True if self.t_ui.exclusion_cb.isChecked() else False
  1209. self.build_tool_ui()
  1210. self.t_ui.exclusion_cb.set_value(self.exclusion_area_cb_is_checked)
  1211. def on_strategy(self, val):
  1212. if val == 'around':
  1213. self.t_ui.over_z_label.setDisabled(True)
  1214. self.t_ui.over_z_entry.setDisabled(True)
  1215. else:
  1216. self.t_ui.over_z_label.setDisabled(False)
  1217. self.t_ui.over_z_entry.setDisabled(False)
  1218. def exclusion_table_toggle_all(self):
  1219. """
  1220. will toggle the selection of all rows in Exclusion Areas table
  1221. :return:
  1222. """
  1223. sel_model = self.t_ui.exclusion_table.selectionModel()
  1224. sel_indexes = sel_model.selectedIndexes()
  1225. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1226. sel_rows = set()
  1227. for idx in sel_indexes:
  1228. sel_rows.add(idx.row())
  1229. if sel_rows:
  1230. self.t_ui.exclusion_table.clearSelection()
  1231. self.delete_sel_shape()
  1232. else:
  1233. self.t_ui.exclusion_table.selectAll()
  1234. self.draw_sel_shape()
  1235. def process_slot_as_drills(self, slot, overlap, add_last_pt=False):
  1236. drills_list = []
  1237. start_pt = slot[0]
  1238. stop_pt = slot[1]
  1239. slot_line = LineString([start_pt, stop_pt])
  1240. drills_list.append(start_pt)
  1241. ii = 0
  1242. while True:
  1243. ii += 1
  1244. target = overlap * ii
  1245. new_pt = slot_line.interpolate(target)
  1246. if new_pt.within(slot_line) is False:
  1247. break
  1248. drills_list.append(new_pt)
  1249. if add_last_pt and stop_pt.distance(drills_list[-1]) >= overlap/10:
  1250. drills_list.append(stop_pt)
  1251. return drills_list
  1252. def on_cnc_button_click(self):
  1253. obj_name = self.t_ui.object_combo.currentText()
  1254. toolchange = self.t_ui.toolchange_cb.get_value()
  1255. # Get source object.
  1256. try:
  1257. obj = self.app.collection.get_by_name(obj_name)
  1258. except Exception:
  1259. self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), str(obj_name)))
  1260. return
  1261. if obj is None:
  1262. self.app.inform.emit('[ERROR_NOTCL] %s.' % _("Object not found"))
  1263. return
  1264. slots_as_drills = self.t_ui.drill_slots_cb.get_value()
  1265. has_drills = None
  1266. for tool_key, tool_dict in self.excellon_tools.items():
  1267. if 'drills' in tool_dict and tool_dict['drills']:
  1268. has_drills = True
  1269. break
  1270. has_slots = None
  1271. for tool_key, tool_dict in self.excellon_tools.items():
  1272. if 'slots' in tool_dict and tool_dict['slots']:
  1273. has_slots = True
  1274. break
  1275. if not has_drills:
  1276. if slots_as_drills and has_slots:
  1277. pass
  1278. else:
  1279. log.debug("camlib.CNCJob.generate_from_excellon_by_tool() --> "
  1280. "The loaded Excellon file has no drills ...")
  1281. self.app.inform.emit('[ERROR_NOTCL] %s...' % _('The loaded Excellon file has no drills'))
  1282. return
  1283. # Get the tools from the Tool Table
  1284. selected_uid = set()
  1285. for sel_it in self.t_ui.tools_table.selectedItems():
  1286. uid = int(self.t_ui.tools_table.item(sel_it.row(), 3).text())
  1287. selected_uid.add(uid)
  1288. selected_tools_id = list(selected_uid)
  1289. if len(selected_tools_id) == 0:
  1290. # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in
  1291. # tool number) it means that there are 3 rows (1 tool and 2 totals).
  1292. # in this case regardless of the selection status of that tool, use it.
  1293. if self.t_ui.tools_table.rowCount() >= 3:
  1294. selected_tools_id.append(int(self.t_ui.tools_table.item(0, 3).text()))
  1295. else:
  1296. self.app.inform.emit('[ERROR_NOTCL] %s' %
  1297. _("Please select one or more tools from the list and try again."))
  1298. return
  1299. xmin = obj.options['xmin']
  1300. ymin = obj.options['ymin']
  1301. xmax = obj.options['xmax']
  1302. ymax = obj.options['ymax']
  1303. job_name = obj.options["name"] + "_cnc"
  1304. obj.pp_excellon_name = self.t_ui.pp_excellon_name_cb.get_value()
  1305. # #############################################################################################################
  1306. # #############################################################################################################
  1307. # TOOLS
  1308. # sort the tools list by the second item in tuple (here we have a dict with diameter of the tool)
  1309. # so we actually are sorting the tools by diameter
  1310. # #############################################################################################################
  1311. # #############################################################################################################
  1312. all_tools = []
  1313. for tool_as_key, v in list(self.excellon_tools.items()):
  1314. all_tools.append((int(tool_as_key), float(v['tooldia'])))
  1315. order = self.t_ui.order_radio.get_value()
  1316. if order == 'fwd':
  1317. sorted_tools = sorted(all_tools, key=lambda t1: t1[1])
  1318. elif order == 'rev':
  1319. sorted_tools = sorted(all_tools, key=lambda t1: t1[1], reverse=True)
  1320. else:
  1321. sorted_tools = all_tools
  1322. # Create a sorted list of selected sel_tools from the sorted_tools list
  1323. sel_tools = [i for i, j in sorted_tools for k in selected_tools_id if i == k]
  1324. log.debug("Tools sorted are: %s" % str(sel_tools))
  1325. # #############################################################################################################
  1326. # #############################################################################################################
  1327. # #############################################################################################################
  1328. # #############################################################################################################
  1329. # Points (Group by tool): a dictionary of shapely Point geo elements grouped by tool number
  1330. # #############################################################################################################
  1331. # #############################################################################################################
  1332. self.app.inform.emit(_("Creating a list of points to drill..."))
  1333. points = {}
  1334. for tool_key, tl_dict in self.excellon_tools.items():
  1335. if tool_key in sel_tools:
  1336. if self.app.abort_flag:
  1337. # graceful abort requested by the user
  1338. raise grace
  1339. if 'drills' in tl_dict and tl_dict['drills']:
  1340. for drill_pt in tl_dict['drills']:
  1341. try:
  1342. points[tool_key].append(drill_pt)
  1343. except KeyError:
  1344. points[tool_key] = [drill_pt]
  1345. log.debug("Found %d TOOLS with drills." % len(points))
  1346. # add slots as drills
  1347. should_add_last_pt = self.t_ui.last_drill_cb.get_value()
  1348. if slots_as_drills:
  1349. for tool_key, tl_dict in self.excellon_tools.items():
  1350. if tool_key in sel_tools:
  1351. if self.app.abort_flag:
  1352. # graceful abort requested by the user
  1353. raise grace
  1354. overlap = 1 - (self.t_ui.drill_overlap_entry.get_value() / 100.0)
  1355. drill_overlap = 0.0
  1356. for i in sorted_tools:
  1357. if i[0] == tool_key:
  1358. slot_tool_dia = i[1]
  1359. drill_overlap = overlap * slot_tool_dia
  1360. break
  1361. new_drills = []
  1362. if 'slots' in tl_dict and tl_dict['slots']:
  1363. for slot in tl_dict['slots']:
  1364. new_drills += self.process_slot_as_drills(slot=slot, overlap=drill_overlap,
  1365. add_last_pt=should_add_last_pt)
  1366. if new_drills:
  1367. try:
  1368. points[tool_key] += new_drills
  1369. except Exception:
  1370. points[tool_key] = new_drills
  1371. log.debug("Found %d TOOLS with drills after converting slots to drills." % len(points))
  1372. # check if there are drill points in the exclusion areas.
  1373. # If we find any within the exclusion areas return 'fail'
  1374. for tool_key in points:
  1375. for pt in points[tool_key]:
  1376. for area in self.app.exc_areas.exclusion_areas_storage:
  1377. pt_buf = pt.buffer(self.exc_tools[tool_key]['tooldia'] / 2.0)
  1378. if pt_buf.within(area['shape']) or pt_buf.intersects(area['shape']):
  1379. self.app.inform.emit("[ERROR_NOTCL] %s" % _("Failed. Drill points inside the exclusion zones."))
  1380. return 'fail'
  1381. # #############################################################################################################
  1382. # General Parameters
  1383. # #############################################################################################################
  1384. used_excellon_optimization_type = self.app.defaults["excellon_optimization_type"]
  1385. current_platform = platform.architecture()[0]
  1386. if current_platform != '64bit':
  1387. used_excellon_optimization_type = 'T'
  1388. # #############################################################################################################
  1389. # #############################################################################################################
  1390. # GCODE creation
  1391. # #############################################################################################################
  1392. # #############################################################################################################
  1393. self.app.inform.emit('%s...' % _("Starting G-Code"))
  1394. # Object initialization function for app.app_obj.new_object()
  1395. def job_init(job_obj, app_obj):
  1396. assert job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
  1397. app_obj.inform.emit(_("Generating Excellon CNCJob..."))
  1398. # #########################################################################################################
  1399. # #########################################################################################################
  1400. # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case of
  1401. # running this method from a Tcl Command
  1402. # #########################################################################################################
  1403. # #########################################################################################################
  1404. build_tools_in_use_list = False
  1405. if 'Tools_in_use' not in job_obj.options:
  1406. job_obj.options['Tools_in_use'] = []
  1407. # if the list is empty (either we just added the key or it was already there but empty) signal to build it
  1408. if not job_obj.options['Tools_in_use']:
  1409. build_tools_in_use_list = True
  1410. # #########################################################################################################
  1411. # #########################################################################################################
  1412. # fill the data into the self.exc_cnc_tools dictionary
  1413. # #########################################################################################################
  1414. # #########################################################################################################
  1415. for it in all_tools:
  1416. for to_ol in sel_tools:
  1417. if to_ol == it[0]:
  1418. sol_geo = []
  1419. drill_no = 0
  1420. if 'drills' in self.excellon_tools[to_ol]:
  1421. drill_no = len(self.excellon_tools[to_ol]['drills'])
  1422. for drill in self.excellon_tools[to_ol]['drills']:
  1423. sol_geo.append(drill.buffer((it[1] / 2.0), resolution=job_obj.geo_steps_per_circle))
  1424. slot_no = 0
  1425. if 'slots' in self.excellon_tools[to_ol]:
  1426. slot_no = len(self.excellon_tools[to_ol]['slots'])
  1427. for slot in self.excellon_tools[to_ol]['slots']:
  1428. start = (slot[0].x, slot[0].y)
  1429. stop = (slot[1].x, slot[1].y)
  1430. sol_geo.append(
  1431. LineString([start, stop]).buffer((it[1] / 2.0),
  1432. resolution=job_obj.geo_steps_per_circle)
  1433. )
  1434. try:
  1435. z_off = float(self.excellon_tools[it[0]]['data']['offset']) * (-1)
  1436. except KeyError:
  1437. z_off = 0
  1438. default_data = {}
  1439. for kk, vv in list(obj.options.items()):
  1440. default_data[kk] = deepcopy(vv)
  1441. job_obj.exc_cnc_tools[it[1]] = {}
  1442. job_obj.exc_cnc_tools[it[1]]['tool'] = it[0]
  1443. job_obj.exc_cnc_tools[it[1]]['nr_drills'] = drill_no
  1444. job_obj.exc_cnc_tools[it[1]]['nr_slots'] = slot_no
  1445. job_obj.exc_cnc_tools[it[1]]['offset'] = z_off
  1446. job_obj.exc_cnc_tools[it[1]]['data'] = default_data
  1447. job_obj.exc_cnc_tools[it[1]]['gcode'] = ''
  1448. job_obj.exc_cnc_tools[it[1]]['gcode_parsed'] = []
  1449. job_obj.exc_cnc_tools[it[1]]['solid_geometry'] = deepcopy(sol_geo)
  1450. # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case
  1451. # of running this method from a Tcl Command
  1452. if build_tools_in_use_list is True:
  1453. job_obj.options['Tools_in_use'].append(
  1454. [it[0], it[1], drill_no, slot_no]
  1455. )
  1456. # #########################################################################################################
  1457. # #########################################################################################################
  1458. # Initialization
  1459. # #########################################################################################################
  1460. # #########################################################################################################
  1461. # Prepprocessor
  1462. job_obj.pp_excellon_name = self.default_data["excellon_ppname_e"]
  1463. job_obj.pp_excellon = self.app.preprocessors[job_obj.pp_excellon_name]
  1464. p = job_obj.pp_excellon
  1465. job_obj.xy_toolchange = self.app.defaults["excellon_toolchangexy"]
  1466. if job_obj.xy_toolchange is not None:
  1467. job_obj.oldx = job_obj.xy_toolchange[0]
  1468. job_obj.oldy = job_obj.xy_toolchange[1]
  1469. else:
  1470. job_obj.oldx = 0.0
  1471. job_obj.oldy = 0.0
  1472. # get the tool_table items in a list of row items
  1473. tool_table_items = self.get_selected_tools_table_items()
  1474. # insert an information only element in the front
  1475. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1476. # ## Add properties to the object
  1477. job_obj.origin_kind = 'excellon'
  1478. job_obj.options['Tools_in_use'] = tool_table_items
  1479. job_obj.options['type'] = 'Excellon'
  1480. job_obj.options['ppname_e'] = obj.pp_excellon_name
  1481. job_obj.toolchange_xy_type = "excellon"
  1482. job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
  1483. job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
  1484. job_obj.options['xmin'] = xmin
  1485. job_obj.options['ymin'] = ymin
  1486. job_obj.options['xmax'] = xmax
  1487. job_obj.options['ymax'] = ymax
  1488. start_gcode = job_obj.doformat(p.start_code)
  1489. job_obj.multitool = True
  1490. if toolchange is True:
  1491. add_start_gcode = True
  1492. for tool in sel_tools:
  1493. tool_points = points[tool]
  1494. used_tooldia = self.excellon_tools[tool]['tooldia']
  1495. if slots_as_drills is True:
  1496. nr_drills = len(points[tool])
  1497. nr_slots = 0
  1498. job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills
  1499. job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots
  1500. for line in range(1, len(job_obj.options['Tools_in_use'])):
  1501. if float('%.*f' % (self.decimals, float(job_obj.options['Tools_in_use'][line][1]))) == \
  1502. float('%.*f' % (self.decimals, used_tooldia)):
  1503. job_obj.options['Tools_in_use'][line][2] = str(nr_drills)
  1504. job_obj.options['Tools_in_use'][line][3] = str(nr_slots)
  1505. tool_gcode = job_obj.gcode_from_excellon_by_tool(tool, tool_points, self.excellon_tools,
  1506. opt_type=used_excellon_optimization_type,
  1507. toolchange=True)
  1508. if add_start_gcode is True:
  1509. tool_gcode = start_gcode + tool_gcode
  1510. add_start_gcode = False
  1511. job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode
  1512. tool_gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia,
  1513. start_pt=(job_obj.oldx, job_obj.oldy))
  1514. job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed
  1515. self.total_gcode += tool_gcode
  1516. self.total_gcode_parsed += tool_gcode_parsed
  1517. else:
  1518. tool_points = []
  1519. for tool in sel_tools:
  1520. tool_points += points[tool]
  1521. used_tool = sel_tools[0]
  1522. used_tooldia = self.excellon_tools[used_tool]['tooldia']
  1523. # those are used by the preprocessors to display data on the toolchange line
  1524. job_obj.tool = str(used_tool)
  1525. job_obj.postdata['toolC'] = used_tooldia
  1526. # reconstitute the tool_table_items to hold the total number of drills and slots since we are going to
  1527. # process all in one go with no toolchange and with only one tool
  1528. nr_drills = 0
  1529. nr_slots = 0
  1530. if slots_as_drills is False:
  1531. for line in range(1, len(tool_table_items)):
  1532. # we may have exception ValueError if there are no drills/slots for the current tool/line
  1533. try:
  1534. nr_drills += int(tool_table_items[line][2])
  1535. except ValueError:
  1536. pass
  1537. try:
  1538. nr_slots += int(tool_table_items[line][3])
  1539. except ValueError:
  1540. pass
  1541. else:
  1542. # if the slots are converted to drills then make slots number = 0 and count the converted drills
  1543. for t in points:
  1544. nr_drills += len(points[t])
  1545. nr_slots = 0
  1546. job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills
  1547. job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots
  1548. tool_table_items.clear()
  1549. tool_table_items = [[str(used_tool), str(used_tooldia), str(nr_drills), str(nr_slots)]]
  1550. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1551. job_obj.options['Tools_in_use'] = tool_table_items
  1552. tool_gcode = start_gcode
  1553. # TODO set the oldx and oldy to start values
  1554. # add a Toolchange event here to load the first tool
  1555. tool_gcode += job_obj.doformat(p.toolchange_code, toolchangexy=(job_obj.oldx, job_obj.oldy))
  1556. tool_gcode += job_obj.gcode_from_excellon_by_tool(used_tool, tool_points, self.excellon_tools,
  1557. opt_type=used_excellon_optimization_type,
  1558. toolchange=False)
  1559. job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode
  1560. tool_gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia,
  1561. start_pt=(job_obj.oldx, job_obj.oldy))
  1562. job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed
  1563. self.total_gcode = tool_gcode
  1564. self.total_gcode_parsed = tool_gcode_parsed
  1565. job_obj.gcode = self.total_gcode
  1566. job_obj.gcode_parsed = self.total_gcode_parsed
  1567. if job_obj.gcode == 'fail':
  1568. return 'fail'
  1569. job_obj.create_geometry()
  1570. if used_excellon_optimization_type == 'M':
  1571. log.debug("The total travel distance with OR-TOOLS Metaheuristics is: %s" %
  1572. str(job_obj.measured_distance))
  1573. elif used_excellon_optimization_type == 'B':
  1574. log.debug("The total travel distance with OR-TOOLS Basic Algorithm is: %s" %
  1575. str(job_obj.measured_distance))
  1576. elif used_excellon_optimization_type == 'T':
  1577. log.debug(
  1578. "The total travel distance with Travelling Salesman Algorithm is: %s" %
  1579. str(job_obj.measured_distance))
  1580. else:
  1581. log.debug("The total travel distance with with no optimization is: %s" %
  1582. str(job_obj.measured_distance))
  1583. # #########################################################################################################
  1584. # ############################# Calculate DISTANCE and ESTIMATED TIME #####################################
  1585. # #########################################################################################################
  1586. if job_obj.xy_end is None:
  1587. job_obj.xy_end = [job_obj.oldx, job_obj.oldy]
  1588. job_obj.measured_distance += abs(distance_euclidian(
  1589. job_obj.oldx, job_obj.oldy, job_obj.xy_end[0], job_obj.xy_end[1])
  1590. )
  1591. log.debug("The total travel distance including travel to end position is: %s" %
  1592. str(job_obj.measured_distance) + '\n')
  1593. job_obj.travel_distance = job_obj.measured_distance
  1594. # I use the value of self.feedrate_rapid for the feadrate in case of the measure_lift_distance and for
  1595. # traveled_time because it is not always possible to determine the feedrate that the CNC machine uses
  1596. # for G0 move (the fastest speed available to the CNC router). Although self.feedrate_rapids is used only
  1597. # with Marlin preprocessor and derivatives.
  1598. job_obj.routing_time = \
  1599. (job_obj.measured_down_distance + job_obj.measured_up_to_zero_distance) / job_obj.feedrate
  1600. lift_time = job_obj.measured_lift_distance / job_obj.feedrate_rapid
  1601. traveled_time = job_obj.measured_distance / job_obj.feedrate_rapid
  1602. job_obj.routing_time += lift_time + traveled_time
  1603. # To be run in separate thread
  1604. def job_thread(a_obj):
  1605. with self.app.proc_container.new(_("Generating CNC Code")):
  1606. a_obj.app_obj.new_object("cncjob", job_name, job_init)
  1607. # Create promise for the new name.
  1608. self.app.collection.promise(job_name)
  1609. # Send to worker
  1610. # self.app.worker.add_task(job_thread, [self.app])
  1611. self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
  1612. def drilling_handler(self, obj):
  1613. pass
  1614. def reset_fields(self):
  1615. self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1616. class DrillingUI:
  1617. toolName = _("Drilling Tool")
  1618. def __init__(self, layout, app):
  1619. self.app = app
  1620. self.decimals = self.app.decimals
  1621. self.layout = layout
  1622. self.tools_frame = QtWidgets.QFrame()
  1623. self.tools_frame.setContentsMargins(0, 0, 0, 0)
  1624. self.layout.addWidget(self.tools_frame)
  1625. self.tools_box = QtWidgets.QVBoxLayout()
  1626. self.tools_box.setContentsMargins(0, 0, 0, 0)
  1627. self.tools_frame.setLayout(self.tools_box)
  1628. self.title_box = QtWidgets.QHBoxLayout()
  1629. self.tools_box.addLayout(self.title_box)
  1630. # ## Title
  1631. title_label = QtWidgets.QLabel("%s" % self.toolName)
  1632. title_label.setStyleSheet("""
  1633. QLabel
  1634. {
  1635. font-size: 16px;
  1636. font-weight: bold;
  1637. }
  1638. """)
  1639. title_label.setToolTip(
  1640. _("Create CNCJob with toolpaths for drilling or milling holes.")
  1641. )
  1642. self.title_box.addWidget(title_label)
  1643. # App Level label
  1644. self.level = QtWidgets.QLabel("")
  1645. self.level.setToolTip(
  1646. _(
  1647. "BASIC is suitable for a beginner. Many parameters\n"
  1648. "are hidden from the user in this mode.\n"
  1649. "ADVANCED mode will make available all parameters.\n\n"
  1650. "To change the application LEVEL, go to:\n"
  1651. "Edit -> Preferences -> General and check:\n"
  1652. "'APP. LEVEL' radio button."
  1653. )
  1654. )
  1655. self.level.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  1656. self.title_box.addWidget(self.level)
  1657. # Grid Layout
  1658. grid0 = QtWidgets.QGridLayout()
  1659. grid0.setColumnStretch(0, 0)
  1660. grid0.setColumnStretch(1, 1)
  1661. self.tools_box.addLayout(grid0)
  1662. self.obj_combo_label = QtWidgets.QLabel('<b>%s</b>:' % _("EXCELLON"))
  1663. self.obj_combo_label.setToolTip(
  1664. _("Excellon object for drilling/milling operation.")
  1665. )
  1666. grid0.addWidget(self.obj_combo_label, 0, 0, 1, 2)
  1667. # ################################################
  1668. # ##### The object to be drilled #################
  1669. # ################################################
  1670. self.object_combo = FCComboBox()
  1671. self.object_combo.setModel(self.app.collection)
  1672. self.object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  1673. # self.object_combo.setCurrentIndex(1)
  1674. self.object_combo.is_last = True
  1675. grid0.addWidget(self.object_combo, 1, 0, 1, 2)
  1676. separator_line = QtWidgets.QFrame()
  1677. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  1678. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  1679. grid0.addWidget(separator_line, 2, 0, 1, 2)
  1680. # ################################################
  1681. # ########## Excellon Tool Table #################
  1682. # ################################################
  1683. self.tools_table = FCTable(drag_drop=True)
  1684. grid0.addWidget(self.tools_table, 3, 0, 1, 2)
  1685. self.tools_table.setColumnCount(5)
  1686. self.tools_table.setColumnHidden(3, True)
  1687. self.tools_table.setSortingEnabled(False)
  1688. self.tools_table.setHorizontalHeaderLabels(['#', _('Diameter'), _('Drills'), '', _('Slots')])
  1689. self.tools_table.horizontalHeaderItem(0).setToolTip(
  1690. _("This is the Tool Number.\n"
  1691. "When ToolChange is checked, on toolchange event this value\n"
  1692. "will be showed as a T1, T2 ... Tn in the Machine Code.\n\n"
  1693. "Here the tools are selected for G-code generation."))
  1694. self.tools_table.horizontalHeaderItem(1).setToolTip(
  1695. _("Tool Diameter. It's value (in current FlatCAM units) \n"
  1696. "is the cut width into the material."))
  1697. self.tools_table.horizontalHeaderItem(2).setToolTip(
  1698. _("The number of Drill holes. Holes that are drilled with\n"
  1699. "a drill bit."))
  1700. self.tools_table.horizontalHeaderItem(4).setToolTip(
  1701. _("The number of Slot holes. Holes that are created by\n"
  1702. "milling them with an endmill bit."))
  1703. # Tool order
  1704. self.order_label = QtWidgets.QLabel('%s:' % _('Tool order'))
  1705. self.order_label.setToolTip(_("This set the way that the tools in the tools table are used.\n"
  1706. "'No' --> means that the used order is the one in the tool table\n"
  1707. "'Forward' --> means that the tools will be ordered from small to big\n"
  1708. "'Reverse' --> means that the tools will ordered from big to small\n\n"
  1709. "WARNING: using rest machining will automatically set the order\n"
  1710. "in reverse and disable this control."))
  1711. self.order_radio = RadioSet([{'label': _('No'), 'value': 'no'},
  1712. {'label': _('Forward'), 'value': 'fwd'},
  1713. {'label': _('Reverse'), 'value': 'rev'}])
  1714. grid0.addWidget(self.order_label, 4, 0)
  1715. grid0.addWidget(self.order_radio, 4, 1)
  1716. separator_line = QtWidgets.QFrame()
  1717. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  1718. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  1719. grid0.addWidget(separator_line, 5, 0, 1, 2)
  1720. # ###########################################################
  1721. # ############# Create CNC Job ##############################
  1722. # ###########################################################
  1723. self.tool_data_label = QtWidgets.QLabel(
  1724. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), int(1)))
  1725. self.tool_data_label.setToolTip(
  1726. _(
  1727. "The data used for creating GCode.\n"
  1728. "Each tool store it's own set of such data."
  1729. )
  1730. )
  1731. grid0.addWidget(self.tool_data_label, 6, 0, 1, 2)
  1732. self.exc_param_frame = QtWidgets.QFrame()
  1733. self.exc_param_frame.setContentsMargins(0, 0, 0, 0)
  1734. grid0.addWidget(self.exc_param_frame, 7, 0, 1, 2)
  1735. self.exc_tools_box = QtWidgets.QVBoxLayout()
  1736. self.exc_tools_box.setContentsMargins(0, 0, 0, 0)
  1737. self.exc_param_frame.setLayout(self.exc_tools_box)
  1738. # #################################################################
  1739. # ################# GRID LAYOUT 3 ###############################
  1740. # #################################################################
  1741. self.grid1 = QtWidgets.QGridLayout()
  1742. self.grid1.setColumnStretch(0, 0)
  1743. self.grid1.setColumnStretch(1, 1)
  1744. self.exc_tools_box.addLayout(self.grid1)
  1745. # Cut Z
  1746. self.cutzlabel = QtWidgets.QLabel('%s:' % _('Cut Z'))
  1747. self.cutzlabel.setToolTip(
  1748. _("Drill depth (negative)\n"
  1749. "below the copper surface.")
  1750. )
  1751. self.cutz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1752. self.cutz_entry.set_precision(self.decimals)
  1753. if machinist_setting == 0:
  1754. self.cutz_entry.set_range(-9999.9999, 0.0000)
  1755. else:
  1756. self.cutz_entry.set_range(-9999.9999, 9999.9999)
  1757. self.cutz_entry.setSingleStep(0.1)
  1758. self.cutz_entry.setObjectName("e_cutz")
  1759. self.grid1.addWidget(self.cutzlabel, 4, 0)
  1760. self.grid1.addWidget(self.cutz_entry, 4, 1)
  1761. # Multi-Depth
  1762. self.mpass_cb = FCCheckBox('%s:' % _("Multi-Depth"))
  1763. self.mpass_cb.setToolTip(
  1764. _(
  1765. "Use multiple passes to limit\n"
  1766. "the cut depth in each pass. Will\n"
  1767. "cut multiple times until Cut Z is\n"
  1768. "reached."
  1769. )
  1770. )
  1771. self.mpass_cb.setObjectName("e_multidepth")
  1772. self.maxdepth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1773. self.maxdepth_entry.set_precision(self.decimals)
  1774. self.maxdepth_entry.set_range(0, 9999.9999)
  1775. self.maxdepth_entry.setSingleStep(0.1)
  1776. self.maxdepth_entry.setToolTip(_("Depth of each pass (positive)."))
  1777. self.maxdepth_entry.setObjectName("e_depthperpass")
  1778. self.mis_mpass_geo = OptionalInputSection(self.mpass_cb, [self.maxdepth_entry])
  1779. self.grid1.addWidget(self.mpass_cb, 5, 0)
  1780. self.grid1.addWidget(self.maxdepth_entry, 5, 1)
  1781. # Travel Z (z_move)
  1782. self.travelzlabel = QtWidgets.QLabel('%s:' % _('Travel Z'))
  1783. self.travelzlabel.setToolTip(
  1784. _("Tool height when travelling\n"
  1785. "across the XY plane.")
  1786. )
  1787. self.travelz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1788. self.travelz_entry.set_precision(self.decimals)
  1789. if machinist_setting == 0:
  1790. self.travelz_entry.set_range(0.00001, 9999.9999)
  1791. else:
  1792. self.travelz_entry.set_range(-9999.9999, 9999.9999)
  1793. self.travelz_entry.setSingleStep(0.1)
  1794. self.travelz_entry.setObjectName("e_travelz")
  1795. self.grid1.addWidget(self.travelzlabel, 6, 0)
  1796. self.grid1.addWidget(self.travelz_entry, 6, 1)
  1797. # Excellon Feedrate Z
  1798. self.frzlabel = QtWidgets.QLabel('%s:' % _('Feedrate Z'))
  1799. self.frzlabel.setToolTip(
  1800. _("Tool speed while drilling\n"
  1801. "(in units per minute).\n"
  1802. "So called 'Plunge' feedrate.\n"
  1803. "This is for linear move G01.")
  1804. )
  1805. self.feedrate_z_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1806. self.feedrate_z_entry.set_precision(self.decimals)
  1807. self.feedrate_z_entry.set_range(0.0, 99999.9999)
  1808. self.feedrate_z_entry.setSingleStep(0.1)
  1809. self.feedrate_z_entry.setObjectName("e_feedratez")
  1810. self.grid1.addWidget(self.frzlabel, 14, 0)
  1811. self.grid1.addWidget(self.feedrate_z_entry, 14, 1)
  1812. # Excellon Rapid Feedrate
  1813. self.feedrate_rapid_label = QtWidgets.QLabel('%s:' % _('Feedrate Rapids'))
  1814. self.feedrate_rapid_label.setToolTip(
  1815. _("Tool speed while drilling\n"
  1816. "(in units per minute).\n"
  1817. "This is for the rapid move G00.\n"
  1818. "It is useful only for Marlin,\n"
  1819. "ignore for any other cases.")
  1820. )
  1821. self.feedrate_rapid_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1822. self.feedrate_rapid_entry.set_precision(self.decimals)
  1823. self.feedrate_rapid_entry.set_range(0.0, 99999.9999)
  1824. self.feedrate_rapid_entry.setSingleStep(0.1)
  1825. self.feedrate_rapid_entry.setObjectName("e_fr_rapid")
  1826. self.grid1.addWidget(self.feedrate_rapid_label, 16, 0)
  1827. self.grid1.addWidget(self.feedrate_rapid_entry, 16, 1)
  1828. # default values is to hide
  1829. self.feedrate_rapid_label.hide()
  1830. self.feedrate_rapid_entry.hide()
  1831. # Spindlespeed
  1832. self.spindle_label = QtWidgets.QLabel('%s:' % _('Spindle speed'))
  1833. self.spindle_label.setToolTip(
  1834. _("Speed of the spindle\n"
  1835. "in RPM (optional)")
  1836. )
  1837. self.spindlespeed_entry = FCSpinner(callback=self.confirmation_message_int)
  1838. self.spindlespeed_entry.set_range(0, 1000000)
  1839. self.spindlespeed_entry.set_step(100)
  1840. self.spindlespeed_entry.setObjectName("e_spindlespeed")
  1841. self.grid1.addWidget(self.spindle_label, 19, 0)
  1842. self.grid1.addWidget(self.spindlespeed_entry, 19, 1)
  1843. # Dwell
  1844. self.dwell_cb = FCCheckBox('%s:' % _('Dwell'))
  1845. self.dwell_cb.setToolTip(
  1846. _("Pause to allow the spindle to reach its\n"
  1847. "speed before cutting.")
  1848. )
  1849. self.dwell_cb.setObjectName("e_dwell")
  1850. # Dwelltime
  1851. self.dwelltime_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1852. self.dwelltime_entry.set_precision(self.decimals)
  1853. self.dwelltime_entry.set_range(0.0, 9999.9999)
  1854. self.dwelltime_entry.setSingleStep(0.1)
  1855. self.dwelltime_entry.setToolTip(
  1856. _("Number of time units for spindle to dwell.")
  1857. )
  1858. self.dwelltime_entry.setObjectName("e_dwelltime")
  1859. self.grid1.addWidget(self.dwell_cb, 20, 0)
  1860. self.grid1.addWidget(self.dwelltime_entry, 20, 1)
  1861. self.ois_dwell = OptionalInputSection(self.dwell_cb, [self.dwelltime_entry])
  1862. # Tool Offset
  1863. self.tool_offset_label = QtWidgets.QLabel('%s:' % _('Offset Z'))
  1864. self.tool_offset_label.setToolTip(
  1865. _("Some drill bits (the larger ones) need to drill deeper\n"
  1866. "to create the desired exit hole diameter due of the tip shape.\n"
  1867. "The value here can compensate the Cut Z parameter.")
  1868. )
  1869. self.offset_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1870. self.offset_entry.set_precision(self.decimals)
  1871. self.offset_entry.set_range(-9999.9999, 9999.9999)
  1872. self.offset_entry.setObjectName("e_offset")
  1873. self.grid1.addWidget(self.tool_offset_label, 25, 0)
  1874. self.grid1.addWidget(self.offset_entry, 25, 1)
  1875. # Drill slots
  1876. self.drill_slots_cb = FCCheckBox('%s' % _('Drill slots'))
  1877. self.drill_slots_cb.setToolTip(
  1878. _("If the selected tool has slots then they will be drilled.")
  1879. )
  1880. self.drill_slots_cb.setObjectName("e_drill_slots")
  1881. self.grid1.addWidget(self.drill_slots_cb, 27, 0, 1, 2)
  1882. # Drill Overlap
  1883. self.drill_overlap_label = QtWidgets.QLabel('%s:' % _('Overlap'))
  1884. self.drill_overlap_label.setToolTip(
  1885. _("How much (percentage) of the tool diameter to overlap previous drill hole.")
  1886. )
  1887. self.drill_overlap_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1888. self.drill_overlap_entry.set_precision(self.decimals)
  1889. self.drill_overlap_entry.set_range(0.0, 100.0000)
  1890. self.drill_overlap_entry.setSingleStep(0.1)
  1891. self.drill_overlap_entry.setObjectName("e_drill_slots_overlap")
  1892. self.grid1.addWidget(self.drill_overlap_label, 28, 0)
  1893. self.grid1.addWidget(self.drill_overlap_entry, 28, 1)
  1894. # Last drill in slot
  1895. self.last_drill_cb = FCCheckBox('%s' % _('Last drill'))
  1896. self.last_drill_cb.setToolTip(
  1897. _("If the slot length is not completely covered by drill holes,\n"
  1898. "add a drill hole on the slot end point.")
  1899. )
  1900. self.last_drill_cb.setObjectName("e_drill_last_drill")
  1901. self.grid1.addWidget(self.last_drill_cb, 30, 0, 1, 2)
  1902. self.ois_drill_overlap = OptionalInputSection(
  1903. self.drill_slots_cb,
  1904. [
  1905. self.drill_overlap_label,
  1906. self.drill_overlap_entry,
  1907. self.last_drill_cb
  1908. ]
  1909. )
  1910. # #################################################################
  1911. # ################# GRID LAYOUT 5 ###############################
  1912. # #################################################################
  1913. # ################# COMMON PARAMETERS #############################
  1914. self.grid3 = QtWidgets.QGridLayout()
  1915. self.grid3.setColumnStretch(0, 0)
  1916. self.grid3.setColumnStretch(1, 1)
  1917. self.exc_tools_box.addLayout(self.grid3)
  1918. separator_line2 = QtWidgets.QFrame()
  1919. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  1920. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  1921. self.grid3.addWidget(separator_line2, 0, 0, 1, 2)
  1922. self.apply_param_to_all = FCButton(_("Apply parameters to all tools"))
  1923. self.apply_param_to_all.setToolTip(
  1924. _("The parameters in the current form will be applied\n"
  1925. "on all the tools from the Tool Table.")
  1926. )
  1927. self.grid3.addWidget(self.apply_param_to_all, 1, 0, 1, 2)
  1928. separator_line2 = QtWidgets.QFrame()
  1929. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  1930. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  1931. self.grid3.addWidget(separator_line2, 2, 0, 1, 2)
  1932. # General Parameters
  1933. self.gen_param_label = QtWidgets.QLabel('<b>%s</b>' % _("Common Parameters"))
  1934. self.gen_param_label.setToolTip(
  1935. _("Parameters that are common for all tools.")
  1936. )
  1937. self.grid3.addWidget(self.gen_param_label, 3, 0, 1, 2)
  1938. # Tool change Z:
  1939. self.toolchange_cb = FCCheckBox('%s:' % _("Tool change Z"))
  1940. self.toolchange_cb.setToolTip(
  1941. _("Include tool-change sequence\n"
  1942. "in G-Code (Pause for tool change).")
  1943. )
  1944. self.toolchangez_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1945. self.toolchangez_entry.set_precision(self.decimals)
  1946. self.toolchangez_entry.setToolTip(
  1947. _("Z-axis position (height) for\n"
  1948. "tool change.")
  1949. )
  1950. if machinist_setting == 0:
  1951. self.toolchangez_entry.set_range(0.0, 9999.9999)
  1952. else:
  1953. self.toolchangez_entry.set_range(-9999.9999, 9999.9999)
  1954. self.toolchangez_entry.setSingleStep(0.1)
  1955. self.ois_tcz_e = OptionalInputSection(self.toolchange_cb, [self.toolchangez_entry])
  1956. self.grid3.addWidget(self.toolchange_cb, 8, 0)
  1957. self.grid3.addWidget(self.toolchangez_entry, 8, 1)
  1958. # Start move Z:
  1959. self.estartz_label = QtWidgets.QLabel('%s:' % _("Start Z"))
  1960. self.estartz_label.setToolTip(
  1961. _("Height of the tool just after start.\n"
  1962. "Delete the value if you don't need this feature.")
  1963. )
  1964. self.estartz_entry = NumericalEvalEntry(border_color='#0069A9')
  1965. self.grid3.addWidget(self.estartz_label, 9, 0)
  1966. self.grid3.addWidget(self.estartz_entry, 9, 1)
  1967. # End move Z:
  1968. self.endz_label = QtWidgets.QLabel('%s:' % _("End move Z"))
  1969. self.endz_label.setToolTip(
  1970. _("Height of the tool after\n"
  1971. "the last move at the end of the job.")
  1972. )
  1973. self.endz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1974. self.endz_entry.set_precision(self.decimals)
  1975. if machinist_setting == 0:
  1976. self.endz_entry.set_range(0.0, 9999.9999)
  1977. else:
  1978. self.endz_entry.set_range(-9999.9999, 9999.9999)
  1979. self.endz_entry.setSingleStep(0.1)
  1980. self.grid3.addWidget(self.endz_label, 11, 0)
  1981. self.grid3.addWidget(self.endz_entry, 11, 1)
  1982. # End Move X,Y
  1983. endmove_xy_label = QtWidgets.QLabel('%s:' % _('End move X,Y'))
  1984. endmove_xy_label.setToolTip(
  1985. _("End move X,Y position. In format (x,y).\n"
  1986. "If no value is entered then there is no move\n"
  1987. "on X,Y plane at the end of the job.")
  1988. )
  1989. self.endxy_entry = NumericalEvalEntry(border_color='#0069A9')
  1990. self.endxy_entry.setPlaceholderText(_("X,Y coordinates"))
  1991. self.grid3.addWidget(endmove_xy_label, 12, 0)
  1992. self.grid3.addWidget(self.endxy_entry, 12, 1)
  1993. # Probe depth
  1994. self.pdepth_label = QtWidgets.QLabel('%s:' % _("Probe Z depth"))
  1995. self.pdepth_label.setToolTip(
  1996. _("The maximum depth that the probe is allowed\n"
  1997. "to probe. Negative value, in current units.")
  1998. )
  1999. self.pdepth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  2000. self.pdepth_entry.set_precision(self.decimals)
  2001. self.pdepth_entry.set_range(-9999.9999, 9999.9999)
  2002. self.pdepth_entry.setSingleStep(0.1)
  2003. self.pdepth_entry.setObjectName("e_depth_probe")
  2004. self.grid3.addWidget(self.pdepth_label, 13, 0)
  2005. self.grid3.addWidget(self.pdepth_entry, 13, 1)
  2006. self.pdepth_label.hide()
  2007. self.pdepth_entry.setVisible(False)
  2008. # Probe feedrate
  2009. self.feedrate_probe_label = QtWidgets.QLabel('%s:' % _("Feedrate Probe"))
  2010. self.feedrate_probe_label.setToolTip(
  2011. _("The feedrate used while the probe is probing.")
  2012. )
  2013. self.feedrate_probe_entry = FCDoubleSpinner(callback=self.confirmation_message)
  2014. self.feedrate_probe_entry.set_precision(self.decimals)
  2015. self.feedrate_probe_entry.set_range(0.0, 9999.9999)
  2016. self.feedrate_probe_entry.setSingleStep(0.1)
  2017. self.feedrate_probe_entry.setObjectName("e_fr_probe")
  2018. self.grid3.addWidget(self.feedrate_probe_label, 14, 0)
  2019. self.grid3.addWidget(self.feedrate_probe_entry, 14, 1)
  2020. self.feedrate_probe_label.hide()
  2021. self.feedrate_probe_entry.setVisible(False)
  2022. # Preprocessor Excellon selection
  2023. pp_excellon_label = QtWidgets.QLabel('%s:' % _("Preprocessor"))
  2024. pp_excellon_label.setToolTip(
  2025. _("The preprocessor JSON file that dictates\n"
  2026. "Gcode output for Excellon Objects.")
  2027. )
  2028. self.pp_excellon_name_cb = FCComboBox()
  2029. self.pp_excellon_name_cb.setFocusPolicy(QtCore.Qt.StrongFocus)
  2030. self.grid3.addWidget(pp_excellon_label, 15, 0)
  2031. self.grid3.addWidget(self.pp_excellon_name_cb, 15, 1)
  2032. # ------------------------------------------------------------------------------------------------------------
  2033. # ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
  2034. # ------------------------------------------------------------------------------------------------------------
  2035. # Exclusion Areas
  2036. self.exclusion_cb = FCCheckBox('%s' % _("Add exclusion areas"))
  2037. self.exclusion_cb.setToolTip(
  2038. _(
  2039. "Include exclusion areas.\n"
  2040. "In those areas the travel of the tools\n"
  2041. "is forbidden."
  2042. )
  2043. )
  2044. self.grid3.addWidget(self.exclusion_cb, 20, 0, 1, 2)
  2045. self.exclusion_frame = QtWidgets.QFrame()
  2046. self.exclusion_frame.setContentsMargins(0, 0, 0, 0)
  2047. self.grid3.addWidget(self.exclusion_frame, 22, 0, 1, 2)
  2048. self.exclusion_box = QtWidgets.QVBoxLayout()
  2049. self.exclusion_box.setContentsMargins(0, 0, 0, 0)
  2050. self.exclusion_frame.setLayout(self.exclusion_box)
  2051. self.exclusion_table = FCTable()
  2052. self.exclusion_box.addWidget(self.exclusion_table)
  2053. self.exclusion_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  2054. self.exclusion_table.setColumnCount(4)
  2055. self.exclusion_table.setColumnWidth(0, 20)
  2056. self.exclusion_table.setHorizontalHeaderLabels(['#', _('Object'), _('Strategy'), _('Over Z')])
  2057. self.exclusion_table.horizontalHeaderItem(0).setToolTip(_("This is the Area ID."))
  2058. self.exclusion_table.horizontalHeaderItem(1).setToolTip(
  2059. _("Type of the object where the exclusion area was added."))
  2060. self.exclusion_table.horizontalHeaderItem(2).setToolTip(
  2061. _("The strategy used for exclusion area. Go around the exclusion areas or over it."))
  2062. self.exclusion_table.horizontalHeaderItem(3).setToolTip(
  2063. _("If the strategy is to go over the area then this is the height at which the tool will go to avoid the "
  2064. "exclusion area."))
  2065. self.exclusion_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
  2066. grid_a1 = QtWidgets.QGridLayout()
  2067. grid_a1.setColumnStretch(0, 0)
  2068. grid_a1.setColumnStretch(1, 1)
  2069. self.exclusion_box.addLayout(grid_a1)
  2070. # Chose Strategy
  2071. self.strategy_label = FCLabel('%s:' % _("Strategy"))
  2072. self.strategy_label.setToolTip(_("The strategy followed when encountering an exclusion area.\n"
  2073. "Can be:\n"
  2074. "- Over -> when encountering the area, the tool will go to a set height\n"
  2075. "- Around -> will avoid the exclusion area by going around the area"))
  2076. self.strategy_radio = RadioSet([{'label': _('Over'), 'value': 'over'},
  2077. {'label': _('Around'), 'value': 'around'}])
  2078. grid_a1.addWidget(self.strategy_label, 1, 0)
  2079. grid_a1.addWidget(self.strategy_radio, 1, 1)
  2080. # Over Z
  2081. self.over_z_label = FCLabel('%s:' % _("Over Z"))
  2082. self.over_z_label.setToolTip(_("The height Z to which the tool will rise in order to avoid\n"
  2083. "an interdiction area."))
  2084. self.over_z_entry = FCDoubleSpinner()
  2085. self.over_z_entry.set_range(0.000, 9999.9999)
  2086. self.over_z_entry.set_precision(self.decimals)
  2087. grid_a1.addWidget(self.over_z_label, 2, 0)
  2088. grid_a1.addWidget(self.over_z_entry, 2, 1)
  2089. # Button Add Area
  2090. self.add_area_button = QtWidgets.QPushButton(_('Add area:'))
  2091. self.add_area_button.setToolTip(_("Add an Exclusion Area."))
  2092. # Area Selection shape
  2093. self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
  2094. {'label': _("Polygon"), 'value': 'polygon'}])
  2095. self.area_shape_radio.setToolTip(
  2096. _("The kind of selection shape used for area selection.")
  2097. )
  2098. grid_a1.addWidget(self.add_area_button, 4, 0)
  2099. grid_a1.addWidget(self.area_shape_radio, 4, 1)
  2100. h_lay_1 = QtWidgets.QHBoxLayout()
  2101. self.exclusion_box.addLayout(h_lay_1)
  2102. # Button Delete All Areas
  2103. self.delete_area_button = QtWidgets.QPushButton(_('Delete All'))
  2104. self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
  2105. # Button Delete Selected Areas
  2106. self.delete_sel_area_button = QtWidgets.QPushButton(_('Delete Selected'))
  2107. self.delete_sel_area_button.setToolTip(_("Delete all exclusion areas that are selected in the table."))
  2108. h_lay_1.addWidget(self.delete_area_button)
  2109. h_lay_1.addWidget(self.delete_sel_area_button)
  2110. self.ois_exclusion_exc = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
  2111. # -------------------------- EXCLUSION AREAS END -------------------------------------------------------------
  2112. # ------------------------------------------------------------------------------------------------------------
  2113. separator_line = QtWidgets.QFrame()
  2114. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  2115. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  2116. self.grid3.addWidget(separator_line, 25, 0, 1, 2)
  2117. # #################################################################
  2118. # ################# GRID LAYOUT 6 ###############################
  2119. # #################################################################
  2120. self.grid4 = QtWidgets.QGridLayout()
  2121. self.grid4.setColumnStretch(0, 0)
  2122. self.grid4.setColumnStretch(1, 1)
  2123. self.tools_box.addLayout(self.grid4)
  2124. self.generate_cnc_button = QtWidgets.QPushButton(_('Generate CNCJob object'))
  2125. self.generate_cnc_button.setToolTip(
  2126. _("Generate the CNC Job.\n"
  2127. "If milling then an additional Geometry object will be created.\n"
  2128. "Add / Select at least one tool in the tool-table.\n"
  2129. "Click the # header to select all, or Ctrl + LMB\n"
  2130. "for custom selection of tools.")
  2131. )
  2132. self.generate_cnc_button.setStyleSheet("""
  2133. QPushButton
  2134. {
  2135. font-weight: bold;
  2136. }
  2137. """)
  2138. self.grid4.addWidget(self.generate_cnc_button, 3, 0, 1, 3)
  2139. self.tools_box.addStretch()
  2140. # ## Reset Tool
  2141. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  2142. self.reset_button.setToolTip(
  2143. _("Will reset the tool parameters.")
  2144. )
  2145. self.reset_button.setStyleSheet("""
  2146. QPushButton
  2147. {
  2148. font-weight: bold;
  2149. }
  2150. """)
  2151. self.tools_box.addWidget(self.reset_button)
  2152. # ############################ FINSIHED GUI ###################################
  2153. # #############################################################################
  2154. def confirmation_message(self, accepted, minval, maxval):
  2155. if accepted is False:
  2156. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  2157. self.decimals,
  2158. minval,
  2159. self.decimals,
  2160. maxval), False)
  2161. else:
  2162. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  2163. def confirmation_message_int(self, accepted, minval, maxval):
  2164. if accepted is False:
  2165. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  2166. (_("Edited value is out of range"), minval, maxval), False)
  2167. else:
  2168. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  2169. def distance(pt1, pt2):
  2170. return np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
  2171. def distance_euclidian(x1, y1, x2, y2):
  2172. return np.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
  2173. class AttrDict(dict):
  2174. def __init__(self, *args, **kwargs):
  2175. super(AttrDict, self).__init__(*args, **kwargs)
  2176. self.__dict__ = self