ToolDrilling.py 119 KB

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