ToolDrilling.py 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658
  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. self.replace_tools()
  715. def replace_tools(self):
  716. log.debug("ToolDrilling.replace_tools()")
  717. if self.excellon_obj:
  718. new_tools_dict = deepcopy(self.excellon_tools)
  719. for orig_tool, orig_tool_val in self.excellon_tools.items():
  720. orig_tooldia = orig_tool_val['tooldia']
  721. # look in database tools
  722. for db_tool, db_tool_val in self.tools_db_dict.items():
  723. db_tooldia = db_tool_val['tooldia']
  724. low_limit = float(db_tool_val['data']['tol_min'])
  725. high_limit = float(db_tool_val['data']['tol_max'])
  726. # if we find a tool with the same diameter in the Tools DB just update it's data
  727. if orig_tooldia == db_tooldia:
  728. for d in db_tool_val['data']:
  729. if d.find('tools_drill') == 0:
  730. new_tools_dict[orig_tool]['data'][d] = db_tool_val['data'][d]
  731. elif d.find('tools_') == 0:
  732. # don't need data for other App Tools; this tests after 'tools_drill_'
  733. continue
  734. else:
  735. new_tools_dict[orig_tool]['data'][d] = db_tool_val['data'][d]
  736. # search for a tool that has a tolerance that the tool fits in
  737. elif high_limit >= orig_tooldia >= low_limit:
  738. new_tools_dict[orig_tool]['tooldia'] = db_tooldia
  739. for d in db_tool_val['data']:
  740. if d.find('tools_drill') == 0:
  741. new_tools_dict[orig_tool]['data'][d] = db_tool_val['data'][d]
  742. elif d.find('tools_') == 0:
  743. # don't need data for other App Tools; this tests after 'tools_drill_'
  744. continue
  745. else:
  746. new_tools_dict[orig_tool]['data'][d] = db_tool_val['data'][d]
  747. self.excellon_tools = new_tools_dict
  748. self.build_tool_ui()
  749. def on_toggle_all_rows(self):
  750. """
  751. will toggle the selection of all rows in Tools table
  752. :return:
  753. """
  754. sel_model = self.t_ui.tools_table.selectionModel()
  755. sel_indexes = sel_model.selectedIndexes()
  756. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  757. sel_rows = set()
  758. for idx in sel_indexes:
  759. sel_rows.add(idx.row())
  760. if len(sel_rows) == self.t_ui.tools_table.rowCount():
  761. self.t_ui.tools_table.clearSelection()
  762. self.t_ui.exc_param_frame.setDisabled(True)
  763. self.t_ui.generate_cnc_button.setDisabled(True)
  764. self.t_ui.tool_data_label.setText(
  765. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
  766. )
  767. else:
  768. self.t_ui.tools_table.selectAll()
  769. self.t_ui.exc_param_frame.setDisabled(False)
  770. self.t_ui.generate_cnc_button.setDisabled(False)
  771. self.t_ui.tool_data_label.setText(
  772. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  773. )
  774. def on_row_selection_change(self):
  775. sel_model = self.t_ui.tools_table.selectionModel()
  776. sel_indexes = sel_model.selectedIndexes()
  777. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  778. sel_rows = set()
  779. for idx in sel_indexes:
  780. sel_rows.add(idx.row())
  781. # update UI only if only one row is selected otherwise having multiple rows selected will deform information
  782. # for the rows other that the current one (first selected)
  783. if len(sel_rows) == 1:
  784. self.update_ui()
  785. def update_ui(self):
  786. self.blockSignals(True)
  787. sel_rows = set()
  788. table_items = self.t_ui.tools_table.selectedItems()
  789. if table_items:
  790. for it in table_items:
  791. sel_rows.add(it.row())
  792. # sel_rows = sorted(set(index.row() for index in self.t_ui.tools_table.selectedIndexes()))
  793. if not sel_rows or len(sel_rows) == 0:
  794. self.t_ui.generate_cnc_button.setDisabled(True)
  795. self.t_ui.exc_param_frame.setDisabled(True)
  796. self.t_ui.tool_data_label.setText(
  797. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
  798. )
  799. self.blockSignals(False)
  800. return
  801. else:
  802. self.t_ui.generate_cnc_button.setDisabled(False)
  803. self.t_ui.exc_param_frame.setDisabled(False)
  804. if len(sel_rows) == 1:
  805. # update the QLabel that shows for which Tool we have the parameters in the UI form
  806. tooluid = int(self.t_ui.tools_table.item(list(sel_rows)[0], 0).text())
  807. self.t_ui.tool_data_label.setText(
  808. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
  809. )
  810. else:
  811. self.t_ui.tool_data_label.setText(
  812. "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
  813. )
  814. for c_row in sel_rows:
  815. # populate the form with the data from the tool associated with the row parameter
  816. try:
  817. item = self.t_ui.tools_table.item(c_row, 3)
  818. if type(item) is not None:
  819. tooluid = int(item.text())
  820. self.storage_to_form(self.excellon_tools[tooluid]['data'])
  821. else:
  822. self.blockSignals(False)
  823. return
  824. except Exception as e:
  825. log.debug("Tool missing. Add a tool in the Tool Table. %s" % str(e))
  826. self.blockSignals(False)
  827. return
  828. self.blockSignals(False)
  829. def storage_to_form(self, dict_storage):
  830. """
  831. Will update the GUI with data from the "storage" in this case the dict self.tools
  832. :param dict_storage: A dictionary holding the data relevant for gnerating Gcode from Excellon
  833. :type dict_storage: dict
  834. :return: None
  835. :rtype:
  836. """
  837. for form_key in self.tool_form_fields:
  838. for storage_key in dict_storage:
  839. if form_key == storage_key and form_key not in \
  840. ["tools_drill_toolchange", "tools_drill_toolchangez", "startz", "endz", "tools_drill_ppname_e"]:
  841. try:
  842. self.tool_form_fields[form_key].set_value(dict_storage[form_key])
  843. except Exception as e:
  844. log.debug("ToolDrilling.storage_to_form() --> %s" % str(e))
  845. pass
  846. def form_to_storage(self):
  847. """
  848. Will update the 'storage' attribute which is the dict self.tools with data collected from GUI
  849. :return: None
  850. :rtype:
  851. """
  852. if self.t_ui.tools_table.rowCount() == 2:
  853. # there is no tool in tool table so we can't save the GUI elements values to storage
  854. # Excellon Tool Table has 2 rows by default
  855. return
  856. self.blockSignals(True)
  857. widget_changed = self.sender()
  858. wdg_objname = widget_changed.objectName()
  859. option_changed = self.name2option[wdg_objname]
  860. # row = self.t_ui.tools_table.currentRow()
  861. rows = sorted(list(set(index.row() for index in self.t_ui.tools_table.selectedIndexes())))
  862. for row in rows:
  863. if row < 0:
  864. row = 0
  865. tooluid_item = int(self.t_ui.tools_table.item(row, 3).text())
  866. # update tool parameters
  867. for tooluid_key, tooluid_val in self.excellon_tools.items():
  868. if int(tooluid_key) == tooluid_item:
  869. if option_changed in self.tool_form_fields:
  870. new_option_value = self.tool_form_fields[option_changed].get_value()
  871. if option_changed in tooluid_val:
  872. tooluid_val[option_changed] = new_option_value
  873. if option_changed in tooluid_val['data']:
  874. tooluid_val['data'][option_changed] = new_option_value
  875. # update general parameters
  876. # they are updated for all tools
  877. for tooluid_key, tooluid_val in self.excellon_tools.items():
  878. if option_changed in self.general_form_fields:
  879. new_option_value = self.general_form_fields[option_changed].get_value()
  880. if option_changed in tooluid_val:
  881. tooluid_val[option_changed] = new_option_value
  882. if option_changed in tooluid_val['data']:
  883. tooluid_val['data'][option_changed] = new_option_value
  884. self.blockSignals(False)
  885. def get_selected_tools_list(self):
  886. """
  887. Returns the keys to the self.tools dictionary corresponding
  888. to the selections on the tool list in the appGUI.
  889. :return: List of tools.
  890. :rtype: list
  891. """
  892. return [str(x.text()) for x in self.t_ui.tools_table.selectedItems()]
  893. def get_selected_tools_table_items(self):
  894. """
  895. Returns a list of lists, each list in the list is made out of row elements
  896. :return: List of table_tools items.
  897. :rtype: list
  898. """
  899. table_tools_items = []
  900. rows = set()
  901. for x in self.t_ui.tools_table.selectedItems():
  902. rows.add(x.row())
  903. for row in rows:
  904. txt = ''
  905. elem = []
  906. for column in range(self.t_ui.tools_table.columnCount()):
  907. if column == 3:
  908. # disregard this column since it's the toolID
  909. continue
  910. try:
  911. txt = self.t_ui.tools_table.item(row, column).text()
  912. except AttributeError:
  913. try:
  914. txt = self.t_ui.tools_table.cellWidget(row, column).currentText()
  915. except AttributeError:
  916. pass
  917. elem.append(txt)
  918. table_tools_items.append(deepcopy(elem))
  919. # table_tools_items.append([self.t_ui.tools_table.item(x.row(), column).text()
  920. # for column in range(0, self.t_ui.tools_table.columnCount() - 1)])
  921. for item in table_tools_items:
  922. item[0] = str(item[0])
  923. return table_tools_items
  924. def on_apply_param_to_all_clicked(self):
  925. if self.t_ui.tools_table.rowCount() == 0:
  926. # there is no tool in tool table so we can't save the GUI elements values to storage
  927. log.debug("ToolDrilling.on_apply_param_to_all_clicked() --> no tool in Tools Table, aborting.")
  928. return
  929. self.blockSignals(True)
  930. row = self.t_ui.tools_table.currentRow()
  931. if row < 0:
  932. row = 0
  933. tooluid_item = int(self.t_ui.tools_table.item(row, 3).text())
  934. temp_tool_data = {}
  935. for tooluid_key, tooluid_val in self.excellon_tools.items():
  936. if int(tooluid_key) == tooluid_item:
  937. # this will hold the 'data' key of the self.tools[tool] dictionary that corresponds to
  938. # the current row in the tool table
  939. temp_tool_data = tooluid_val['data']
  940. break
  941. for tooluid_key, tooluid_val in self.excellon_tools.items():
  942. tooluid_val['data'] = deepcopy(temp_tool_data)
  943. self.app.inform.emit('[success] %s' % _("Current Tool parameters were applied to all tools."))
  944. self.blockSignals(False)
  945. def on_order_changed(self, order):
  946. if order != 'no':
  947. self.build_tool_ui()
  948. def on_tooltable_cellwidget_change(self):
  949. cw = self.sender()
  950. assert isinstance(cw, QtWidgets.QComboBox), \
  951. "Expected a QtWidgets.QComboBox, got %s" % isinstance(cw, QtWidgets.QComboBox)
  952. cw_index = self.t_ui.tools_table.indexAt(cw.pos())
  953. cw_row = cw_index.row()
  954. cw_col = cw_index.column()
  955. current_uid = int(self.t_ui.tools_table.item(cw_row, 3).text())
  956. # if the sender is in the column with index 2 then we update the tool_type key
  957. if cw_col == 2:
  958. tt = cw.currentText()
  959. typ = 'Iso' if tt == 'V' else "Rough"
  960. self.excellon_tools[current_uid].update({
  961. 'type': typ,
  962. 'tool_type': tt,
  963. })
  964. def on_pp_changed(self):
  965. current_pp = self.t_ui.pp_excellon_name_cb.get_value()
  966. if "toolchange_probe" in current_pp.lower():
  967. self.t_ui.pdepth_entry.setVisible(True)
  968. self.t_ui.pdepth_label.show()
  969. self.t_ui.feedrate_probe_entry.setVisible(True)
  970. self.t_ui.feedrate_probe_label.show()
  971. else:
  972. self.t_ui.pdepth_entry.setVisible(False)
  973. self.t_ui.pdepth_label.hide()
  974. self.t_ui.feedrate_probe_entry.setVisible(False)
  975. self.t_ui.feedrate_probe_label.hide()
  976. if 'marlin' in current_pp.lower():
  977. self.t_ui.feedrate_rapid_label.show()
  978. self.t_ui.feedrate_rapid_entry.show()
  979. else:
  980. self.t_ui.feedrate_rapid_label.hide()
  981. self.t_ui.feedrate_rapid_entry.hide()
  982. if 'laser' in current_pp.lower():
  983. self.t_ui.cutzlabel.hide()
  984. self.t_ui.cutz_entry.hide()
  985. try:
  986. self.t_ui.mpass_cb.hide()
  987. self.t_ui.maxdepth_entry.hide()
  988. except AttributeError:
  989. pass
  990. if 'marlin' in current_pp.lower():
  991. self.t_ui.travelzlabel.setText('%s:' % _("Focus Z"))
  992. self.t_ui.travelzlabel.show()
  993. self.t_ui.travelz_entry.show()
  994. self.t_ui.endz_label.show()
  995. self.t_ui.endz_entry.show()
  996. else:
  997. self.t_ui.travelzlabel.hide()
  998. self.t_ui.travelz_entry.hide()
  999. self.t_ui.endz_label.hide()
  1000. self.t_ui.endz_entry.hide()
  1001. try:
  1002. self.t_ui.frzlabel.hide()
  1003. self.t_ui.feedrate_z_entry.hide()
  1004. except AttributeError:
  1005. pass
  1006. self.t_ui.dwell_cb.hide()
  1007. self.t_ui.dwelltime_entry.hide()
  1008. self.t_ui.spindle_label.setText('%s:' % _("Laser Power"))
  1009. try:
  1010. self.t_ui.tool_offset_label.hide()
  1011. self.t_ui.offset_entry.hide()
  1012. except AttributeError:
  1013. pass
  1014. else:
  1015. self.t_ui.cutzlabel.show()
  1016. self.t_ui.cutz_entry.show()
  1017. try:
  1018. self.t_ui.mpass_cb.show()
  1019. self.t_ui.maxdepth_entry.show()
  1020. except AttributeError:
  1021. pass
  1022. self.t_ui.travelzlabel.setText('%s:' % _('Travel Z'))
  1023. self.t_ui.travelzlabel.show()
  1024. self.t_ui.travelz_entry.show()
  1025. self.t_ui.endz_label.show()
  1026. self.t_ui.endz_entry.show()
  1027. try:
  1028. self.t_ui.frzlabel.show()
  1029. self.t_ui.feedrate_z_entry.show()
  1030. except AttributeError:
  1031. pass
  1032. self.t_ui.dwell_cb.show()
  1033. self.t_ui.dwelltime_entry.show()
  1034. self.t_ui.spindle_label.setText('%s:' % _('Spindle speed'))
  1035. try:
  1036. self.t_ui.tool_offset_label.show()
  1037. self.t_ui.offset_entry.show()
  1038. except AttributeError:
  1039. pass
  1040. def on_key_press(self, event):
  1041. # modifiers = QtWidgets.QApplication.keyboardModifiers()
  1042. # matplotlib_key_flag = False
  1043. # events out of the self.app.collection view (it's about Project Tab) are of type int
  1044. if type(event) is int:
  1045. key = event
  1046. # events from the GUI are of type QKeyEvent
  1047. elif type(event) == QtGui.QKeyEvent:
  1048. key = event.key()
  1049. elif isinstance(event, mpl_key_event): # MatPlotLib key events are trickier to interpret than the rest
  1050. # matplotlib_key_flag = True
  1051. key = event.key
  1052. key = QtGui.QKeySequence(key)
  1053. # check for modifiers
  1054. key_string = key.toString().lower()
  1055. if '+' in key_string:
  1056. mod, __, key_text = key_string.rpartition('+')
  1057. if mod.lower() == 'ctrl':
  1058. # modifiers = QtCore.Qt.ControlModifier
  1059. pass
  1060. elif mod.lower() == 'alt':
  1061. # modifiers = QtCore.Qt.AltModifier
  1062. pass
  1063. elif mod.lower() == 'shift':
  1064. # modifiers = QtCore.Qt.ShiftModifier
  1065. pass
  1066. else:
  1067. # modifiers = QtCore.Qt.NoModifier
  1068. pass
  1069. key = QtGui.QKeySequence(key_text)
  1070. # events from Vispy are of type KeyEvent
  1071. else:
  1072. key = event.key
  1073. if key == QtCore.Qt.Key_Escape or key == 'Escape':
  1074. self.points = []
  1075. self.poly_drawn = False
  1076. self.delete_moving_selection_shape()
  1077. self.delete_tool_selection_shape()
  1078. def on_add_area_click(self):
  1079. shape_button = self.t_ui.area_shape_radio
  1080. overz_button = self.t_ui.over_z_entry
  1081. strategy_radio = self.t_ui.strategy_radio
  1082. cnc_button = self.t_ui.generate_cnc_button
  1083. solid_geo = self.excellon_obj.solid_geometry
  1084. obj_type = self.excellon_obj.kind
  1085. self.app.exc_areas.on_add_area_click(
  1086. shape_button=shape_button, overz_button=overz_button, cnc_button=cnc_button, strategy_radio=strategy_radio,
  1087. solid_geo=solid_geo, obj_type=obj_type)
  1088. def on_clear_area_click(self):
  1089. if not self.app.exc_areas.exclusion_areas_storage:
  1090. self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. There are no exclusion areas to delete."))
  1091. return
  1092. self.app.exc_areas.on_clear_area_click()
  1093. self.app.exc_areas.e_shape_modified.emit()
  1094. def on_delete_sel_areas(self):
  1095. sel_model = self.t_ui.exclusion_table.selectionModel()
  1096. sel_indexes = sel_model.selectedIndexes()
  1097. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1098. # so the duplicate rows will not be added
  1099. sel_rows = set()
  1100. for idx in sel_indexes:
  1101. sel_rows.add(idx.row())
  1102. if not sel_rows:
  1103. self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. Nothing is selected."))
  1104. return
  1105. self.app.exc_areas.delete_sel_shapes(idxs=list(sel_rows))
  1106. self.app.exc_areas.e_shape_modified.emit()
  1107. def draw_sel_shape(self):
  1108. sel_model = self.t_ui.exclusion_table.selectionModel()
  1109. sel_indexes = sel_model.selectedIndexes()
  1110. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1111. sel_rows = set()
  1112. for idx in sel_indexes:
  1113. sel_rows.add(idx.row())
  1114. self.delete_sel_shape()
  1115. if self.app.is_legacy is False:
  1116. face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.2 * 255)))[2:]
  1117. outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(0.8 * 255)))[2:]
  1118. else:
  1119. face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.4 * 255)))[2:]
  1120. outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(1.0 * 255)))[2:]
  1121. for row in sel_rows:
  1122. sel_rect = self.app.exc_areas.exclusion_areas_storage[row]['shape']
  1123. self.app.move_tool.sel_shapes.add(sel_rect, color=outline, face_color=face, update=True, layer=0,
  1124. tolerance=None)
  1125. if self.app.is_legacy is True:
  1126. self.app.move_tool.sel_shapes.redraw()
  1127. def clear_selection(self):
  1128. self.app.delete_selection_shape()
  1129. # self.t_ui.exclusion_table.clearSelection()
  1130. def delete_sel_shape(self):
  1131. self.app.delete_selection_shape()
  1132. def update_exclusion_table(self):
  1133. self.exclusion_area_cb_is_checked = True if self.t_ui.exclusion_cb.isChecked() else False
  1134. self.build_tool_ui()
  1135. self.t_ui.exclusion_cb.set_value(self.exclusion_area_cb_is_checked)
  1136. def on_strategy(self, val):
  1137. if val == 'around':
  1138. self.t_ui.over_z_label.setDisabled(True)
  1139. self.t_ui.over_z_entry.setDisabled(True)
  1140. else:
  1141. self.t_ui.over_z_label.setDisabled(False)
  1142. self.t_ui.over_z_entry.setDisabled(False)
  1143. def exclusion_table_toggle_all(self):
  1144. """
  1145. will toggle the selection of all rows in Exclusion Areas table
  1146. :return:
  1147. """
  1148. sel_model = self.t_ui.exclusion_table.selectionModel()
  1149. sel_indexes = sel_model.selectedIndexes()
  1150. # it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
  1151. sel_rows = set()
  1152. for idx in sel_indexes:
  1153. sel_rows.add(idx.row())
  1154. if sel_rows:
  1155. self.t_ui.exclusion_table.clearSelection()
  1156. self.delete_sel_shape()
  1157. else:
  1158. self.t_ui.exclusion_table.selectAll()
  1159. self.draw_sel_shape()
  1160. @staticmethod
  1161. def process_slot_as_drills(slot, overlap, add_last_pt=False):
  1162. drills_list = []
  1163. start_pt = slot[0]
  1164. stop_pt = slot[1]
  1165. slot_line = LineString([start_pt, stop_pt])
  1166. drills_list.append(start_pt)
  1167. ii = 0
  1168. while True:
  1169. ii += 1
  1170. target = overlap * ii
  1171. new_pt = slot_line.interpolate(target)
  1172. if new_pt.within(slot_line) is False:
  1173. break
  1174. drills_list.append(new_pt)
  1175. if add_last_pt and stop_pt.distance(drills_list[-1]) >= overlap/10:
  1176. drills_list.append(stop_pt)
  1177. return drills_list
  1178. def is_valid_excellon(self):
  1179. slots_as_drills = self.t_ui.drill_slots_cb.get_value()
  1180. has_drills = None
  1181. for tool_key, tool_dict in self.excellon_tools.items():
  1182. if 'drills' in tool_dict and tool_dict['drills']:
  1183. has_drills = True
  1184. break
  1185. has_slots = None
  1186. for tool_key, tool_dict in self.excellon_tools.items():
  1187. if 'slots' in tool_dict and tool_dict['slots']:
  1188. has_slots = True
  1189. break
  1190. if not has_drills:
  1191. if slots_as_drills and has_slots:
  1192. return True
  1193. else:
  1194. return False
  1195. def get_selected_tools_uid(self):
  1196. """
  1197. Return a list of the selected tools UID from the Tool Table
  1198. """
  1199. selected_uid = set()
  1200. for sel_it in self.t_ui.tools_table.selectedItems():
  1201. uid = int(self.t_ui.tools_table.item(sel_it.row(), 3).text())
  1202. selected_uid.add(uid)
  1203. return list(selected_uid)
  1204. def create_drill_points(self, selected_tools, selected_sorted_tools):
  1205. points = {}
  1206. # create drill points out of the drills locations
  1207. for tool_key, tl_dict in self.excellon_tools.items():
  1208. if tool_key in selected_tools:
  1209. if 'drills' in tl_dict and tl_dict['drills']:
  1210. for drill_pt in tl_dict['drills']:
  1211. try:
  1212. points[tool_key].append(drill_pt)
  1213. except KeyError:
  1214. points[tool_key] = [drill_pt]
  1215. log.debug("Found %d TOOLS with drills." % len(points))
  1216. # #############################################################################################################
  1217. # ############ SLOTS TO DRILLS CONVERSION SECTION #############################################################
  1218. # #############################################################################################################
  1219. # convert slots to a sequence of drills and add them to drill points
  1220. should_add_last_pt = self.t_ui.last_drill_cb.get_value()
  1221. for tool_key, tl_dict in self.excellon_tools.items():
  1222. convert_slots = tl_dict['data']['tools_drill_drill_slots']
  1223. if convert_slots:
  1224. if tool_key in selected_tools:
  1225. overlap = 1 - (self.t_ui.drill_overlap_entry.get_value() / 100.0)
  1226. drill_overlap = 0.0
  1227. for i in selected_sorted_tools:
  1228. if i[0] == tool_key:
  1229. slot_tool_dia = i[1]
  1230. drill_overlap = overlap * slot_tool_dia
  1231. break
  1232. new_drills = []
  1233. if 'slots' in tl_dict and tl_dict['slots']:
  1234. for slot in tl_dict['slots']:
  1235. new_drills += self.process_slot_as_drills(slot=slot, overlap=drill_overlap,
  1236. add_last_pt=should_add_last_pt)
  1237. if new_drills:
  1238. try:
  1239. points[tool_key] += new_drills
  1240. except Exception:
  1241. points[tool_key] = new_drills
  1242. log.debug("Found %d TOOLS with drills after converting slots to drills." % len(points))
  1243. return points
  1244. def check_intersection(self, points):
  1245. for tool_key in points:
  1246. for pt in points[tool_key]:
  1247. for area in self.app.exc_areas.exclusion_areas_storage:
  1248. pt_buf = pt.buffer(self.excellon_tools[tool_key]['tooldia'] / 2.0)
  1249. if pt_buf.within(area['shape']) or pt_buf.intersects(area['shape']):
  1250. return True
  1251. return False
  1252. def on_cnc_button_click(self):
  1253. obj_name = self.t_ui.object_combo.currentText()
  1254. toolchange = self.t_ui.toolchange_cb.get_value()
  1255. # Get source object.
  1256. try:
  1257. obj = self.app.collection.get_by_name(obj_name)
  1258. except Exception:
  1259. self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), str(obj_name)))
  1260. return
  1261. if obj is None:
  1262. self.app.inform.emit('[ERROR_NOTCL] %s.' % _("Object not found"))
  1263. return
  1264. xmin = obj.options['xmin']
  1265. ymin = obj.options['ymin']
  1266. xmax = obj.options['xmax']
  1267. ymax = obj.options['ymax']
  1268. job_name = obj.options["name"] + "_cnc"
  1269. obj.pp_excellon_name = self.t_ui.pp_excellon_name_cb.get_value()
  1270. if self.is_valid_excellon() is False:
  1271. log.debug("camlib.CNCJob.generate_from_excellon_by_tool() --> "
  1272. "The loaded Excellon file has no drills ...")
  1273. self.app.inform.emit('[ERROR_NOTCL] %s...' % _('The loaded Excellon file has no drills'))
  1274. return
  1275. # Get the tools from the Tool Table
  1276. selected_tools_id = self.get_selected_tools_uid()
  1277. if not selected_tools_id:
  1278. # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in
  1279. # tool number) it means that there are 3 rows (1 tool and 2 totals).
  1280. # in this case regardless of the selection status of that tool, use it.
  1281. if self.t_ui.tools_table.rowCount() >= 3:
  1282. selected_tools_id.append(int(self.t_ui.tools_table.item(0, 3).text()))
  1283. else:
  1284. msg = '[ERROR_NOTCL] %s' % _("Please select one or more tools from the list and try again.")
  1285. self.app.inform.emit(msg)
  1286. return
  1287. # #############################################################################################################
  1288. # #############################################################################################################
  1289. # TOOLS
  1290. # sort the tools list by the second item in tuple (here we have a dict with diameter of the tool)
  1291. # so we actually are sorting the tools by diameter
  1292. # #############################################################################################################
  1293. # #############################################################################################################
  1294. all_tools = []
  1295. for tool_as_key, v in list(self.excellon_tools.items()):
  1296. all_tools.append((int(tool_as_key), float(v['tooldia'])))
  1297. order = self.t_ui.order_radio.get_value()
  1298. if order == 'fwd':
  1299. sorted_tools = sorted(all_tools, key=lambda t1: t1[1])
  1300. elif order == 'rev':
  1301. sorted_tools = sorted(all_tools, key=lambda t1: t1[1], reverse=True)
  1302. else:
  1303. sorted_tools = all_tools
  1304. # Create a sorted list of selected sel_tools from the sorted_tools list
  1305. sel_tools = [i for i, j in sorted_tools for k in selected_tools_id if i == k]
  1306. log.debug("Tools sorted are: %s" % str(sel_tools))
  1307. # #############################################################################################################
  1308. # #############################################################################################################
  1309. # #### Create Points (Group by tool): a dictionary of shapely Point geo elements grouped by tool number #######
  1310. # #############################################################################################################
  1311. # #############################################################################################################
  1312. self.app.inform.emit(_("Creating a list of points to drill..."))
  1313. # points is a dictionary: keys are tools ad values are lists of Shapely Points
  1314. points = self.create_drill_points(selected_tools=sel_tools, selected_sorted_tools=sorted_tools)
  1315. # check if there are drill points in the exclusion areas (if any areas)
  1316. if self.app.exc_areas.exclusion_areas_storage and self.check_intersection(points) is True:
  1317. self.app.inform.emit("[ERROR_NOTCL] %s" % _("Failed. Drill points inside the exclusion zones."))
  1318. return 'fail'
  1319. # #############################################################################################################
  1320. # General Parameters
  1321. # #############################################################################################################
  1322. used_excellon_optimization_type = self.app.defaults["excellon_optimization_type"]
  1323. current_platform = platform.architecture()[0]
  1324. if current_platform != '64bit':
  1325. used_excellon_optimization_type = 'T'
  1326. # #############################################################################################################
  1327. # #############################################################################################################
  1328. # GCODE creation
  1329. # #############################################################################################################
  1330. # #############################################################################################################
  1331. self.app.inform.emit('%s...' % _("Starting G-Code"))
  1332. # Object initialization function for app.app_obj.new_object()
  1333. def job_init(job_obj, app_obj):
  1334. assert job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
  1335. app_obj.inform.emit(_("Generating Excellon CNCJob..."))
  1336. # #########################################################################################################
  1337. # #########################################################################################################
  1338. # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case of
  1339. # running this method from a Tcl Command
  1340. # #########################################################################################################
  1341. # #########################################################################################################
  1342. build_tools_in_use_list = False
  1343. if 'Tools_in_use' not in job_obj.options:
  1344. job_obj.options['Tools_in_use'] = []
  1345. # if the list is empty (either we just added the key or it was already there but empty) signal to build it
  1346. if not job_obj.options['Tools_in_use']:
  1347. build_tools_in_use_list = True
  1348. # #########################################################################################################
  1349. # #########################################################################################################
  1350. # fill the data into the self.exc_cnc_tools dictionary
  1351. # #########################################################################################################
  1352. # #########################################################################################################
  1353. for it in all_tools:
  1354. for to_ol in sel_tools:
  1355. if to_ol == it[0]:
  1356. sol_geo = []
  1357. # solid geometry addition; we look into points because we may have slots converted to drills
  1358. # therefore more drills than there were originally in
  1359. # the self.excellon_tools[to_ol]['drills'] list
  1360. drill_no = 0
  1361. if to_ol in points and points[to_ol]:
  1362. drill_no = len(points[to_ol])
  1363. for drill in points[to_ol]:
  1364. sol_geo.append(drill.buffer((it[1] / 2.0), resolution=job_obj.geo_steps_per_circle))
  1365. slot_no = 0
  1366. convert_slots = self.excellon_tools[to_ol]['data']['tools_drill_drill_slots']
  1367. if 'slots' in self.excellon_tools[to_ol] and convert_slots is False:
  1368. slot_no = len(self.excellon_tools[to_ol]['slots'])
  1369. for eslot in self.excellon_tools[to_ol]['slots']:
  1370. start = (eslot[0].x, eslot[0].y)
  1371. stop = (eslot[1].x, eslot[1].y)
  1372. sol_geo.append(
  1373. LineString([start, stop]).buffer((it[1] / 2.0),
  1374. resolution=job_obj.geo_steps_per_circle)
  1375. )
  1376. # adjust Offset for current tool
  1377. try:
  1378. z_off = float(self.excellon_tools[it[0]]['data']['offset']) * (-1)
  1379. except KeyError:
  1380. z_off = 0
  1381. # default tool data
  1382. default_data = {}
  1383. for kk, vv in list(obj.options.items()):
  1384. default_data[kk] = deepcopy(vv)
  1385. default_data['tools_drill_cutz'] = float(self.excellon_tools[it[0]]['data']['tools_drill_cutz'])
  1386. # populate the Excellon CNC tools storage
  1387. job_obj.exc_cnc_tools[it[1]] = {}
  1388. job_obj.exc_cnc_tools[it[1]]['tool'] = it[0]
  1389. job_obj.exc_cnc_tools[it[1]]['nr_drills'] = drill_no
  1390. job_obj.exc_cnc_tools[it[1]]['nr_slots'] = slot_no
  1391. job_obj.exc_cnc_tools[it[1]]['offset'] = z_off
  1392. job_obj.exc_cnc_tools[it[1]]['data'] = default_data
  1393. job_obj.exc_cnc_tools[it[1]]['gcode'] = ''
  1394. job_obj.exc_cnc_tools[it[1]]['gcode_parsed'] = []
  1395. job_obj.exc_cnc_tools[it[1]]['solid_geometry'] = deepcopy(sol_geo)
  1396. # build a self.options['Tools_in_use'] list from scratch if we don't have one like in the case
  1397. # of running this method from a Tcl Command
  1398. if build_tools_in_use_list is True:
  1399. job_obj.options['Tools_in_use'].append(
  1400. [it[0], it[1], drill_no, slot_no]
  1401. )
  1402. # #########################################################################################################
  1403. # #########################################################################################################
  1404. # Initialization
  1405. # #########################################################################################################
  1406. # #########################################################################################################
  1407. # Preprocessor
  1408. job_obj.pp_excellon_name = self.t_ui.pp_excellon_name_cb.get_value()
  1409. job_obj.pp_excellon = self.app.preprocessors[job_obj.pp_excellon_name]
  1410. # get the tool_table items in a list of row items
  1411. tool_table_items = self.get_selected_tools_table_items()
  1412. # insert an information only element in the front
  1413. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1414. # ## Add properties to the object
  1415. job_obj.options['Tools_in_use'] = tool_table_items
  1416. job_obj.options['type'] = 'Excellon'
  1417. job_obj.options['ppname_e'] = obj.pp_excellon_name
  1418. job_obj.options['xmin'] = xmin
  1419. job_obj.options['ymin'] = ymin
  1420. job_obj.options['xmax'] = xmax
  1421. job_obj.options['ymax'] = ymax
  1422. job_obj.origin_kind = 'excellon'
  1423. job_obj.use_ui = True
  1424. job_obj.toolchange_xy_type = "excellon"
  1425. job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
  1426. job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
  1427. job_obj.multitool = True
  1428. # first drill point
  1429. job_obj.xy_toolchange = self.app.defaults["tools_drill_toolchangexy"]
  1430. x_tc, y_tc = [0, 0]
  1431. try:
  1432. if job_obj.xy_toolchange != '':
  1433. tcxy_temp = re.sub('[()\[\]]', '', str(job_obj.xy_toolchange))
  1434. if tcxy_temp:
  1435. x_tc, y_tc = [float(eval(a)) for a in tcxy_temp.split(",")]
  1436. except Exception:
  1437. x_tc, y_tc = [0, 0]
  1438. self.app.inform.emit('[ERROR]%s' % _("The Toolchange X,Y format has to be (x, y)."))
  1439. job_obj.oldx = x_tc
  1440. job_obj.oldy = y_tc
  1441. first_drill_point = (job_obj.oldx, job_obj.oldy)
  1442. # #########################################################################################################
  1443. # ####################### NO TOOLCHANGE ###################################################################
  1444. # #########################################################################################################
  1445. if toolchange is False:
  1446. tool_points = []
  1447. for tool in sel_tools:
  1448. tool_points += points[tool]
  1449. # use the first tool in the selection as the tool that we are going to use
  1450. used_tool = sel_tools[0]
  1451. used_tooldia = self.excellon_tools[used_tool]['tooldia']
  1452. # those are used by the preprocessors to display data on the toolchange line
  1453. job_obj.tool = str(used_tool)
  1454. job_obj.postdata['toolC'] = used_tooldia
  1455. # reconstitute the tool_table_items to hold the total number of drills and slots since we are going to
  1456. # process all in one go with no toolchange and with only one tool
  1457. nr_drills = 0
  1458. nr_slots = 0
  1459. total_solid_geo = []
  1460. # calculate the total number of drills and of slots
  1461. for e_tool_dia in job_obj.exc_cnc_tools:
  1462. nr_drills += int(job_obj.exc_cnc_tools[e_tool_dia]['nr_drills'])
  1463. nr_slots += int(job_obj.exc_cnc_tools[e_tool_dia]['nr_slots'])
  1464. total_solid_geo += job_obj.exc_cnc_tools[e_tool_dia]['solid_geometry']
  1465. tool_table_items.clear()
  1466. tool_table_items = [[str(used_tool), str(used_tooldia), str(nr_drills), str(nr_slots)]]
  1467. tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
  1468. job_obj.options['Tools_in_use'] = tool_table_items
  1469. # generate GCode
  1470. tool_gcode, __, start_gcode = job_obj.excellon_tool_gcode_gen(used_tool, tool_points,
  1471. self.excellon_tools,
  1472. first_pt=first_drill_point,
  1473. is_first=True,
  1474. is_last=True,
  1475. opt_type=used_excellon_optimization_type,
  1476. toolchange=True)
  1477. # parse the Gcode
  1478. tool_gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia, gcode=tool_gcode,
  1479. start_pt=first_drill_point)
  1480. # store the results in Excellon CNC tools storage
  1481. job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills
  1482. job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots
  1483. job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode
  1484. job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed
  1485. job_obj.exc_cnc_tools[used_tooldia]['solid_geometry'] = total_solid_geo
  1486. # delete all tools from the Excellon CNC tools storage except the used one
  1487. for e_tool_dia in list(job_obj.exc_cnc_tools.keys()):
  1488. if e_tool_dia != used_tooldia:
  1489. job_obj.exc_cnc_tools.pop(e_tool_dia, None)
  1490. if start_gcode != '':
  1491. job_obj.gc_start = start_gcode
  1492. self.total_gcode = tool_gcode
  1493. self.total_gcode_parsed = tool_gcode_parsed
  1494. # ####################### TOOLCHANGE ACTIVE ######################################################
  1495. else:
  1496. for tool in sel_tools:
  1497. tool_points = points[tool]
  1498. used_tooldia = self.excellon_tools[tool]['tooldia']
  1499. # if slots are converted to drill for this tool, update the number of drills and make slots nr zero
  1500. convert_slots = self.excellon_tools[tool]['data']['tools_drill_drill_slots']
  1501. if convert_slots is True:
  1502. nr_drills = len(points[tool])
  1503. nr_slots = 0
  1504. job_obj.exc_cnc_tools[used_tooldia]['nr_drills'] = nr_drills
  1505. job_obj.exc_cnc_tools[used_tooldia]['nr_slots'] = nr_slots
  1506. for line in range(1, len(job_obj.options['Tools_in_use'])):
  1507. if self.dec_format(float(job_obj.options['Tools_in_use'][line][1])) == \
  1508. self.dec_format(used_tooldia):
  1509. job_obj.options['Tools_in_use'][line][2] = str(nr_drills)
  1510. job_obj.options['Tools_in_use'][line][3] = str(nr_slots)
  1511. # calculate if the current tool is the first one or if it is the last one
  1512. # for the first tool we add some extra GCode (start Gcode, header etc)
  1513. # for the last tool we add other GCode (the end code, what is happening at the end of the job)
  1514. is_last_tool = True if tool == sel_tools[-1] else False
  1515. is_first_tool = True if tool == sel_tools[0] else False
  1516. # Generate Gcode for the current tool
  1517. tool_gcode, last_pt, start_gcode = job_obj.excellon_tool_gcode_gen(
  1518. tool, tool_points, self.excellon_tools,
  1519. first_pt=first_drill_point,
  1520. is_first=is_first_tool,
  1521. is_last=is_last_tool,
  1522. opt_type=used_excellon_optimization_type,
  1523. toolchange=True)
  1524. # parse Gcode for the current tool
  1525. tool_gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia, gcode=tool_gcode,
  1526. start_pt=first_drill_point)
  1527. first_drill_point = last_pt
  1528. # store the results of GCode generation and parsing
  1529. job_obj.exc_cnc_tools[used_tooldia]['gcode'] = tool_gcode
  1530. job_obj.exc_cnc_tools[used_tooldia]['gcode_parsed'] = tool_gcode_parsed
  1531. if start_gcode != '':
  1532. job_obj.gc_start = start_gcode
  1533. self.total_gcode += tool_gcode
  1534. self.total_gcode_parsed += tool_gcode_parsed
  1535. job_obj.gcode = self.total_gcode
  1536. job_obj.source_file = self.total_gcode
  1537. job_obj.gcode_parsed = self.total_gcode_parsed
  1538. if job_obj.gcode == 'fail':
  1539. return 'fail'
  1540. # create Geometry for plotting
  1541. # FIXME is it necessary? didn't we do it previously when filling data in self.exc_cnc_tools dictionary?
  1542. job_obj.create_geometry()
  1543. if used_excellon_optimization_type == 'M':
  1544. log.debug("The total travel distance with OR-TOOLS Metaheuristics is: %s" %
  1545. str(job_obj.measured_distance))
  1546. elif used_excellon_optimization_type == 'B':
  1547. log.debug("The total travel distance with OR-TOOLS Basic Algorithm is: %s" %
  1548. str(job_obj.measured_distance))
  1549. elif used_excellon_optimization_type == 'T':
  1550. log.debug(
  1551. "The total travel distance with Travelling Salesman Algorithm is: %s" %
  1552. str(job_obj.measured_distance))
  1553. else:
  1554. log.debug("The total travel distance with with no optimization is: %s" %
  1555. str(job_obj.measured_distance))
  1556. # #########################################################################################################
  1557. # ############################# Calculate DISTANCE and ESTIMATED TIME #####################################
  1558. # #########################################################################################################
  1559. if job_obj.xy_end is None:
  1560. job_obj.xy_end = [job_obj.oldx, job_obj.oldy]
  1561. job_obj.measured_distance += abs(distance_euclidian(
  1562. job_obj.oldx, job_obj.oldy, job_obj.xy_end[0], job_obj.xy_end[1])
  1563. )
  1564. log.debug("The total travel distance including travel to end position is: %s" %
  1565. str(job_obj.measured_distance) + '\n')
  1566. job_obj.travel_distance = job_obj.measured_distance
  1567. # I use the value of self.feedrate_rapid for the feadrate in case of the measure_lift_distance and for
  1568. # traveled_time because it is not always possible to determine the feedrate that the CNC machine uses
  1569. # for G0 move (the fastest speed available to the CNC router). Although self.feedrate_rapids is used only
  1570. # with Marlin preprocessor and derivatives.
  1571. job_obj.routing_time = \
  1572. (job_obj.measured_down_distance + job_obj.measured_up_to_zero_distance) / job_obj.z_feedrate
  1573. lift_time = job_obj.measured_lift_distance / job_obj.feedrate_rapid
  1574. traveled_time = job_obj.measured_distance / job_obj.feedrate_rapid
  1575. job_obj.routing_time += lift_time + traveled_time
  1576. # To be run in separate thread
  1577. def job_thread(a_obj):
  1578. with self.app.proc_container.new(_("Generating CNC Code")):
  1579. a_obj.app_obj.new_object("cncjob", job_name, job_init)
  1580. # Switch notebook to Selected page
  1581. self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
  1582. # Create promise for the new name.
  1583. self.app.collection.promise(job_name)
  1584. # Send to worker
  1585. # self.app.worker.add_task(job_thread, [self.app])
  1586. self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
  1587. def reset_fields(self):
  1588. self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  1589. class DrillingUI:
  1590. toolName = _("Drilling Tool")
  1591. def __init__(self, layout, app):
  1592. self.app = app
  1593. self.decimals = self.app.decimals
  1594. self.layout = layout
  1595. self.tools_frame = QtWidgets.QFrame()
  1596. self.tools_frame.setContentsMargins(0, 0, 0, 0)
  1597. self.layout.addWidget(self.tools_frame)
  1598. self.tools_box = QtWidgets.QVBoxLayout()
  1599. self.tools_box.setContentsMargins(0, 0, 0, 0)
  1600. self.tools_frame.setLayout(self.tools_box)
  1601. self.title_box = QtWidgets.QHBoxLayout()
  1602. self.tools_box.addLayout(self.title_box)
  1603. # ## Title
  1604. title_label = QtWidgets.QLabel("%s" % self.toolName)
  1605. title_label.setStyleSheet("""
  1606. QLabel
  1607. {
  1608. font-size: 16px;
  1609. font-weight: bold;
  1610. }
  1611. """)
  1612. title_label.setToolTip(
  1613. _("Create CNCJob with toolpaths for drilling or milling holes.")
  1614. )
  1615. self.title_box.addWidget(title_label)
  1616. # App Level label
  1617. self.level = QtWidgets.QLabel("")
  1618. self.level.setToolTip(
  1619. _(
  1620. "BASIC is suitable for a beginner. Many parameters\n"
  1621. "are hidden from the user in this mode.\n"
  1622. "ADVANCED mode will make available all parameters.\n\n"
  1623. "To change the application LEVEL, go to:\n"
  1624. "Edit -> Preferences -> General and check:\n"
  1625. "'APP. LEVEL' radio button."
  1626. )
  1627. )
  1628. self.level.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  1629. self.title_box.addWidget(self.level)
  1630. # Grid Layout
  1631. grid0 = QtWidgets.QGridLayout()
  1632. grid0.setColumnStretch(0, 0)
  1633. grid0.setColumnStretch(1, 1)
  1634. self.tools_box.addLayout(grid0)
  1635. self.obj_combo_label = QtWidgets.QLabel('<b>%s</b>:' % _("EXCELLON"))
  1636. self.obj_combo_label.setToolTip(
  1637. _("Excellon object for drilling/milling operation.")
  1638. )
  1639. grid0.addWidget(self.obj_combo_label, 0, 0, 1, 2)
  1640. # ################################################
  1641. # ##### The object to be drilled #################
  1642. # ################################################
  1643. self.object_combo = FCComboBox()
  1644. self.object_combo.setModel(self.app.collection)
  1645. self.object_combo.setRootModelIndex(self.app.collection.index(1, 0, QtCore.QModelIndex()))
  1646. # self.object_combo.setCurrentIndex(1)
  1647. self.object_combo.is_last = True
  1648. grid0.addWidget(self.object_combo, 1, 0, 1, 2)
  1649. separator_line = QtWidgets.QFrame()
  1650. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  1651. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  1652. grid0.addWidget(separator_line, 2, 0, 1, 2)
  1653. # ################################################
  1654. # ########## Excellon Tool Table #################
  1655. # ################################################
  1656. self.tools_table = FCTable(drag_drop=True)
  1657. grid0.addWidget(self.tools_table, 3, 0, 1, 2)
  1658. self.tools_table.setColumnCount(5)
  1659. self.tools_table.setColumnHidden(3, True)
  1660. self.tools_table.setSortingEnabled(False)
  1661. self.tools_table.setHorizontalHeaderLabels(['#', _('Diameter'), _('Drills'), '', _('Slots')])
  1662. self.tools_table.horizontalHeaderItem(0).setToolTip(
  1663. _("This is the Tool Number.\n"
  1664. "When ToolChange is checked, on toolchange event this value\n"
  1665. "will be showed as a T1, T2 ... Tn in the Machine Code.\n\n"
  1666. "Here the tools are selected for G-code generation."))
  1667. self.tools_table.horizontalHeaderItem(1).setToolTip(
  1668. _("Tool Diameter. It's value (in current FlatCAM units) \n"
  1669. "is the cut width into the material."))
  1670. self.tools_table.horizontalHeaderItem(2).setToolTip(
  1671. _("The number of Drill holes. Holes that are drilled with\n"
  1672. "a drill bit."))
  1673. self.tools_table.horizontalHeaderItem(4).setToolTip(
  1674. _("The number of Slot holes. Holes that are created by\n"
  1675. "milling them with an endmill bit."))
  1676. # Tool order
  1677. self.order_label = QtWidgets.QLabel('%s:' % _('Tool order'))
  1678. self.order_label.setToolTip(_("This set the way that the tools in the tools table are used.\n"
  1679. "'No' --> means that the used order is the one in the tool table\n"
  1680. "'Forward' --> means that the tools will be ordered from small to big\n"
  1681. "'Reverse' --> means that the tools will ordered from big to small\n\n"
  1682. "WARNING: using rest machining will automatically set the order\n"
  1683. "in reverse and disable this control."))
  1684. self.order_radio = RadioSet([{'label': _('No'), 'value': 'no'},
  1685. {'label': _('Forward'), 'value': 'fwd'},
  1686. {'label': _('Reverse'), 'value': 'rev'}])
  1687. grid0.addWidget(self.order_label, 4, 0)
  1688. grid0.addWidget(self.order_radio, 4, 1)
  1689. # Manual Load of Tools from DB
  1690. self.search_load_db_btn = FCButton(_("Search DB"))
  1691. self.search_load_db_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/search_db32.png'))
  1692. self.search_load_db_btn.setToolTip(
  1693. _("Will search and try to replace the tools from Tools Table\n"
  1694. "with tools from DB that have a close diameter value.")
  1695. )
  1696. grid0.addWidget(self.search_load_db_btn, 5, 0, 1, 2)
  1697. separator_line = QtWidgets.QFrame()
  1698. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  1699. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  1700. grid0.addWidget(separator_line, 6, 0, 1, 2)
  1701. # ###########################################################
  1702. # ############# Create CNC Job ##############################
  1703. # ###########################################################
  1704. self.tool_data_label = QtWidgets.QLabel(
  1705. "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), int(1)))
  1706. self.tool_data_label.setToolTip(
  1707. _(
  1708. "The data used for creating GCode.\n"
  1709. "Each tool store it's own set of such data."
  1710. )
  1711. )
  1712. grid0.addWidget(self.tool_data_label, 8, 0, 1, 2)
  1713. self.exc_param_frame = QtWidgets.QFrame()
  1714. self.exc_param_frame.setContentsMargins(0, 0, 0, 0)
  1715. grid0.addWidget(self.exc_param_frame, 10, 0, 1, 2)
  1716. self.exc_tools_box = QtWidgets.QVBoxLayout()
  1717. self.exc_tools_box.setContentsMargins(0, 0, 0, 0)
  1718. self.exc_param_frame.setLayout(self.exc_tools_box)
  1719. # #################################################################
  1720. # ################# GRID LAYOUT 3 ###############################
  1721. # #################################################################
  1722. self.grid1 = QtWidgets.QGridLayout()
  1723. self.grid1.setColumnStretch(0, 0)
  1724. self.grid1.setColumnStretch(1, 1)
  1725. self.exc_tools_box.addLayout(self.grid1)
  1726. # Cut Z
  1727. self.cutzlabel = QtWidgets.QLabel('%s:' % _('Cut Z'))
  1728. self.cutzlabel.setToolTip(
  1729. _("Drill depth (negative)\n"
  1730. "below the copper surface.")
  1731. )
  1732. self.cutz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1733. self.cutz_entry.set_precision(self.decimals)
  1734. if machinist_setting == 0:
  1735. self.cutz_entry.set_range(-9999.9999, 0.0000)
  1736. else:
  1737. self.cutz_entry.set_range(-9999.9999, 9999.9999)
  1738. self.cutz_entry.setSingleStep(0.1)
  1739. self.cutz_entry.setObjectName("e_cutz")
  1740. self.grid1.addWidget(self.cutzlabel, 4, 0)
  1741. self.grid1.addWidget(self.cutz_entry, 4, 1)
  1742. # Multi-Depth
  1743. self.mpass_cb = FCCheckBox('%s:' % _("Multi-Depth"))
  1744. self.mpass_cb.setToolTip(
  1745. _(
  1746. "Use multiple passes to limit\n"
  1747. "the cut depth in each pass. Will\n"
  1748. "cut multiple times until Cut Z is\n"
  1749. "reached."
  1750. )
  1751. )
  1752. self.mpass_cb.setObjectName("e_multidepth")
  1753. self.maxdepth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1754. self.maxdepth_entry.set_precision(self.decimals)
  1755. self.maxdepth_entry.set_range(0, 9999.9999)
  1756. self.maxdepth_entry.setSingleStep(0.1)
  1757. self.maxdepth_entry.setToolTip(_("Depth of each pass (positive)."))
  1758. self.maxdepth_entry.setObjectName("e_depthperpass")
  1759. self.mis_mpass_geo = OptionalInputSection(self.mpass_cb, [self.maxdepth_entry])
  1760. self.grid1.addWidget(self.mpass_cb, 5, 0)
  1761. self.grid1.addWidget(self.maxdepth_entry, 5, 1)
  1762. # Travel Z (z_move)
  1763. self.travelzlabel = QtWidgets.QLabel('%s:' % _('Travel Z'))
  1764. self.travelzlabel.setToolTip(
  1765. _("Tool height when travelling\n"
  1766. "across the XY plane.")
  1767. )
  1768. self.travelz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1769. self.travelz_entry.set_precision(self.decimals)
  1770. if machinist_setting == 0:
  1771. self.travelz_entry.set_range(0.00001, 9999.9999)
  1772. else:
  1773. self.travelz_entry.set_range(-9999.9999, 9999.9999)
  1774. self.travelz_entry.setSingleStep(0.1)
  1775. self.travelz_entry.setObjectName("e_travelz")
  1776. self.grid1.addWidget(self.travelzlabel, 6, 0)
  1777. self.grid1.addWidget(self.travelz_entry, 6, 1)
  1778. # Excellon Feedrate Z
  1779. self.frzlabel = QtWidgets.QLabel('%s:' % _('Feedrate Z'))
  1780. self.frzlabel.setToolTip(
  1781. _("Tool speed while drilling\n"
  1782. "(in units per minute).\n"
  1783. "So called 'Plunge' feedrate.\n"
  1784. "This is for linear move G01.")
  1785. )
  1786. self.feedrate_z_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1787. self.feedrate_z_entry.set_precision(self.decimals)
  1788. self.feedrate_z_entry.set_range(0.0, 99999.9999)
  1789. self.feedrate_z_entry.setSingleStep(0.1)
  1790. self.feedrate_z_entry.setObjectName("e_feedratez")
  1791. self.grid1.addWidget(self.frzlabel, 14, 0)
  1792. self.grid1.addWidget(self.feedrate_z_entry, 14, 1)
  1793. # Excellon Rapid Feedrate
  1794. self.feedrate_rapid_label = QtWidgets.QLabel('%s:' % _('Feedrate Rapids'))
  1795. self.feedrate_rapid_label.setToolTip(
  1796. _("Tool speed while drilling\n"
  1797. "(in units per minute).\n"
  1798. "This is for the rapid move G00.\n"
  1799. "It is useful only for Marlin,\n"
  1800. "ignore for any other cases.")
  1801. )
  1802. self.feedrate_rapid_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1803. self.feedrate_rapid_entry.set_precision(self.decimals)
  1804. self.feedrate_rapid_entry.set_range(0.0, 99999.9999)
  1805. self.feedrate_rapid_entry.setSingleStep(0.1)
  1806. self.feedrate_rapid_entry.setObjectName("e_fr_rapid")
  1807. self.grid1.addWidget(self.feedrate_rapid_label, 16, 0)
  1808. self.grid1.addWidget(self.feedrate_rapid_entry, 16, 1)
  1809. # default values is to hide
  1810. self.feedrate_rapid_label.hide()
  1811. self.feedrate_rapid_entry.hide()
  1812. # Spindlespeed
  1813. self.spindle_label = QtWidgets.QLabel('%s:' % _('Spindle speed'))
  1814. self.spindle_label.setToolTip(
  1815. _("Speed of the spindle\n"
  1816. "in RPM (optional)")
  1817. )
  1818. self.spindlespeed_entry = FCSpinner(callback=self.confirmation_message_int)
  1819. self.spindlespeed_entry.set_range(0, 1000000)
  1820. self.spindlespeed_entry.set_step(100)
  1821. self.spindlespeed_entry.setObjectName("e_spindlespeed")
  1822. self.grid1.addWidget(self.spindle_label, 19, 0)
  1823. self.grid1.addWidget(self.spindlespeed_entry, 19, 1)
  1824. # Dwell
  1825. self.dwell_cb = FCCheckBox('%s:' % _('Dwell'))
  1826. self.dwell_cb.setToolTip(
  1827. _("Pause to allow the spindle to reach its\n"
  1828. "speed before cutting.")
  1829. )
  1830. self.dwell_cb.setObjectName("e_dwell")
  1831. # Dwelltime
  1832. self.dwelltime_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1833. self.dwelltime_entry.set_precision(self.decimals)
  1834. self.dwelltime_entry.set_range(0.0, 9999.9999)
  1835. self.dwelltime_entry.setSingleStep(0.1)
  1836. self.dwelltime_entry.setToolTip(
  1837. _("Number of time units for spindle to dwell.")
  1838. )
  1839. self.dwelltime_entry.setObjectName("e_dwelltime")
  1840. self.grid1.addWidget(self.dwell_cb, 20, 0)
  1841. self.grid1.addWidget(self.dwelltime_entry, 20, 1)
  1842. self.ois_dwell = OptionalInputSection(self.dwell_cb, [self.dwelltime_entry])
  1843. # Tool Offset
  1844. self.tool_offset_label = QtWidgets.QLabel('%s:' % _('Offset Z'))
  1845. self.tool_offset_label.setToolTip(
  1846. _("Some drill bits (the larger ones) need to drill deeper\n"
  1847. "to create the desired exit hole diameter due of the tip shape.\n"
  1848. "The value here can compensate the Cut Z parameter.")
  1849. )
  1850. self.offset_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1851. self.offset_entry.set_precision(self.decimals)
  1852. self.offset_entry.set_range(-9999.9999, 9999.9999)
  1853. self.offset_entry.setObjectName("e_offset")
  1854. self.grid1.addWidget(self.tool_offset_label, 25, 0)
  1855. self.grid1.addWidget(self.offset_entry, 25, 1)
  1856. # Drill slots
  1857. self.drill_slots_cb = FCCheckBox('%s' % _('Drill slots'))
  1858. self.drill_slots_cb.setToolTip(
  1859. _("If the selected tool has slots then they will be drilled.")
  1860. )
  1861. self.drill_slots_cb.setObjectName("e_drill_slots")
  1862. self.grid1.addWidget(self.drill_slots_cb, 27, 0, 1, 2)
  1863. # Drill Overlap
  1864. self.drill_overlap_label = QtWidgets.QLabel('%s:' % _('Overlap'))
  1865. self.drill_overlap_label.setToolTip(
  1866. _("How much (percentage) of the tool diameter to overlap previous drill hole.")
  1867. )
  1868. self.drill_overlap_entry = FCDoubleSpinner(suffix='%', callback=self.confirmation_message)
  1869. self.drill_overlap_entry.set_precision(self.decimals)
  1870. self.drill_overlap_entry.set_range(0.0, 100.0000)
  1871. self.drill_overlap_entry.setSingleStep(0.1)
  1872. self.drill_overlap_entry.setObjectName("e_drill_slots_overlap")
  1873. self.grid1.addWidget(self.drill_overlap_label, 28, 0)
  1874. self.grid1.addWidget(self.drill_overlap_entry, 28, 1)
  1875. # Last drill in slot
  1876. self.last_drill_cb = FCCheckBox('%s' % _('Last drill'))
  1877. self.last_drill_cb.setToolTip(
  1878. _("If the slot length is not completely covered by drill holes,\n"
  1879. "add a drill hole on the slot end point.")
  1880. )
  1881. self.last_drill_cb.setObjectName("e_drill_last_drill")
  1882. self.grid1.addWidget(self.last_drill_cb, 30, 0, 1, 2)
  1883. self.drill_overlap_label.hide()
  1884. self.drill_overlap_entry.hide()
  1885. self.last_drill_cb.hide()
  1886. self.ois_drill_overlap = OptionalHideInputSection(
  1887. self.drill_slots_cb,
  1888. [
  1889. self.drill_overlap_label,
  1890. self.drill_overlap_entry,
  1891. self.last_drill_cb
  1892. ]
  1893. )
  1894. # #################################################################
  1895. # ################# GRID LAYOUT 5 ###############################
  1896. # #################################################################
  1897. # ################# COMMON PARAMETERS #############################
  1898. self.grid3 = QtWidgets.QGridLayout()
  1899. self.grid3.setColumnStretch(0, 0)
  1900. self.grid3.setColumnStretch(1, 1)
  1901. self.exc_tools_box.addLayout(self.grid3)
  1902. separator_line2 = QtWidgets.QFrame()
  1903. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  1904. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  1905. self.grid3.addWidget(separator_line2, 0, 0, 1, 2)
  1906. self.apply_param_to_all = FCButton(_("Apply parameters to all tools"))
  1907. self.apply_param_to_all.setIcon(QtGui.QIcon(self.app.resource_location + '/param_all32.png'))
  1908. self.apply_param_to_all.setToolTip(
  1909. _("The parameters in the current form will be applied\n"
  1910. "on all the tools from the Tool Table.")
  1911. )
  1912. self.grid3.addWidget(self.apply_param_to_all, 1, 0, 1, 2)
  1913. separator_line2 = QtWidgets.QFrame()
  1914. separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
  1915. separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
  1916. self.grid3.addWidget(separator_line2, 2, 0, 1, 2)
  1917. # General Parameters
  1918. self.gen_param_label = QtWidgets.QLabel('<b>%s</b>' % _("Common Parameters"))
  1919. self.gen_param_label.setToolTip(
  1920. _("Parameters that are common for all tools.")
  1921. )
  1922. self.grid3.addWidget(self.gen_param_label, 3, 0, 1, 2)
  1923. # Tool change
  1924. self.toolchange_cb = FCCheckBox('%s' % _("Tool change"))
  1925. self.toolchange_cb.setToolTip(
  1926. _("Include tool-change sequence\n"
  1927. "in G-Code (Pause for tool change).")
  1928. )
  1929. self.toolchange_cb.setObjectName("e_toolchange")
  1930. self.grid3.addWidget(self.toolchange_cb, 5, 0, 1, 2)
  1931. # Toolchange Z
  1932. self.toolchangez_label = QtWidgets.QLabel('%s:' % _("Tool change Z"))
  1933. self.toolchangez_label.setToolTip(
  1934. _("Z-axis position (height) for\n"
  1935. "tool change.")
  1936. )
  1937. self.toolchangez_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1938. self.toolchangez_entry.set_precision(self.decimals)
  1939. self.toolchangez_entry.setObjectName("e_toolchangez")
  1940. if machinist_setting == 0:
  1941. self.toolchangez_entry.set_range(0.0, 9999.9999)
  1942. else:
  1943. self.toolchangez_entry.set_range(-9999.9999, 9999.9999)
  1944. self.toolchangez_entry.setSingleStep(0.1)
  1945. self.grid3.addWidget(self.toolchangez_label, 7, 0)
  1946. self.grid3.addWidget(self.toolchangez_entry, 7, 1)
  1947. # Start move Z:
  1948. self.estartz_label = QtWidgets.QLabel('%s:' % _("Start Z"))
  1949. self.estartz_label.setToolTip(
  1950. _("Height of the tool just after start.\n"
  1951. "Delete the value if you don't need this feature.")
  1952. )
  1953. self.estartz_entry = NumericalEvalEntry(border_color='#0069A9')
  1954. self.estartz_entry.setObjectName("e_startz")
  1955. self.grid3.addWidget(self.estartz_label, 9, 0)
  1956. self.grid3.addWidget(self.estartz_entry, 9, 1)
  1957. # End move Z:
  1958. self.endz_label = QtWidgets.QLabel('%s:' % _("End move Z"))
  1959. self.endz_label.setToolTip(
  1960. _("Height of the tool after\n"
  1961. "the last move at the end of the job.")
  1962. )
  1963. self.endz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1964. self.endz_entry.set_precision(self.decimals)
  1965. self.endz_entry.setObjectName("e_endz")
  1966. if machinist_setting == 0:
  1967. self.endz_entry.set_range(0.0, 9999.9999)
  1968. else:
  1969. self.endz_entry.set_range(-9999.9999, 9999.9999)
  1970. self.endz_entry.setSingleStep(0.1)
  1971. self.grid3.addWidget(self.endz_label, 11, 0)
  1972. self.grid3.addWidget(self.endz_entry, 11, 1)
  1973. # End Move X,Y
  1974. endmove_xy_label = QtWidgets.QLabel('%s:' % _('End move X,Y'))
  1975. endmove_xy_label.setToolTip(
  1976. _("End move X,Y position. In format (x,y).\n"
  1977. "If no value is entered then there is no move\n"
  1978. "on X,Y plane at the end of the job.")
  1979. )
  1980. self.endxy_entry = NumericalEvalEntry(border_color='#0069A9')
  1981. self.endxy_entry.setPlaceholderText(_("X,Y coordinates"))
  1982. self.endxy_entry.setObjectName("e_endxy")
  1983. self.grid3.addWidget(endmove_xy_label, 12, 0)
  1984. self.grid3.addWidget(self.endxy_entry, 12, 1)
  1985. # Probe depth
  1986. self.pdepth_label = QtWidgets.QLabel('%s:' % _("Probe Z depth"))
  1987. self.pdepth_label.setToolTip(
  1988. _("The maximum depth that the probe is allowed\n"
  1989. "to probe. Negative value, in current units.")
  1990. )
  1991. self.pdepth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1992. self.pdepth_entry.set_precision(self.decimals)
  1993. self.pdepth_entry.set_range(-9999.9999, 9999.9999)
  1994. self.pdepth_entry.setSingleStep(0.1)
  1995. self.pdepth_entry.setObjectName("e_depth_probe")
  1996. self.grid3.addWidget(self.pdepth_label, 13, 0)
  1997. self.grid3.addWidget(self.pdepth_entry, 13, 1)
  1998. self.pdepth_label.hide()
  1999. self.pdepth_entry.setVisible(False)
  2000. # Probe feedrate
  2001. self.feedrate_probe_label = QtWidgets.QLabel('%s:' % _("Feedrate Probe"))
  2002. self.feedrate_probe_label.setToolTip(
  2003. _("The feedrate used while the probe is probing.")
  2004. )
  2005. self.feedrate_probe_entry = FCDoubleSpinner(callback=self.confirmation_message)
  2006. self.feedrate_probe_entry.set_precision(self.decimals)
  2007. self.feedrate_probe_entry.set_range(0.0, 9999.9999)
  2008. self.feedrate_probe_entry.setSingleStep(0.1)
  2009. self.feedrate_probe_entry.setObjectName("e_fr_probe")
  2010. self.grid3.addWidget(self.feedrate_probe_label, 14, 0)
  2011. self.grid3.addWidget(self.feedrate_probe_entry, 14, 1)
  2012. self.feedrate_probe_label.hide()
  2013. self.feedrate_probe_entry.setVisible(False)
  2014. # Preprocessor Excellon selection
  2015. pp_excellon_label = QtWidgets.QLabel('%s:' % _("Preprocessor"))
  2016. pp_excellon_label.setToolTip(
  2017. _("The preprocessor JSON file that dictates\n"
  2018. "Gcode output for Excellon Objects.")
  2019. )
  2020. self.pp_excellon_name_cb = FCComboBox()
  2021. self.pp_excellon_name_cb.setFocusPolicy(QtCore.Qt.StrongFocus)
  2022. self.pp_excellon_name_cb.setObjectName("e_pp")
  2023. self.grid3.addWidget(pp_excellon_label, 15, 0)
  2024. self.grid3.addWidget(self.pp_excellon_name_cb, 15, 1)
  2025. # ------------------------------------------------------------------------------------------------------------
  2026. # ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
  2027. # ------------------------------------------------------------------------------------------------------------
  2028. # Exclusion Areas
  2029. self.exclusion_cb = FCCheckBox('%s' % _("Add exclusion areas"))
  2030. self.exclusion_cb.setToolTip(
  2031. _(
  2032. "Include exclusion areas.\n"
  2033. "In those areas the travel of the tools\n"
  2034. "is forbidden."
  2035. ))
  2036. self.exclusion_cb.setObjectName("e_area_exclusion")
  2037. self.grid3.addWidget(self.exclusion_cb, 20, 0, 1, 2)
  2038. self.exclusion_frame = QtWidgets.QFrame()
  2039. self.exclusion_frame.setContentsMargins(0, 0, 0, 0)
  2040. self.grid3.addWidget(self.exclusion_frame, 22, 0, 1, 2)
  2041. self.exclusion_box = QtWidgets.QVBoxLayout()
  2042. self.exclusion_box.setContentsMargins(0, 0, 0, 0)
  2043. self.exclusion_frame.setLayout(self.exclusion_box)
  2044. self.exclusion_table = FCTable()
  2045. self.exclusion_box.addWidget(self.exclusion_table)
  2046. self.exclusion_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  2047. self.exclusion_table.setColumnCount(4)
  2048. self.exclusion_table.setColumnWidth(0, 20)
  2049. self.exclusion_table.setHorizontalHeaderLabels(['#', _('Object'), _('Strategy'), _('Over Z')])
  2050. self.exclusion_table.horizontalHeaderItem(0).setToolTip(_("This is the Area ID."))
  2051. self.exclusion_table.horizontalHeaderItem(1).setToolTip(
  2052. _("Type of the object where the exclusion area was added."))
  2053. self.exclusion_table.horizontalHeaderItem(2).setToolTip(
  2054. _("The strategy used for exclusion area. Go around the exclusion areas or over it."))
  2055. self.exclusion_table.horizontalHeaderItem(3).setToolTip(
  2056. _("If the strategy is to go over the area then this is the height at which the tool will go to avoid the "
  2057. "exclusion area."))
  2058. self.exclusion_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
  2059. grid_a1 = QtWidgets.QGridLayout()
  2060. grid_a1.setColumnStretch(0, 0)
  2061. grid_a1.setColumnStretch(1, 1)
  2062. self.exclusion_box.addLayout(grid_a1)
  2063. # Chose Strategy
  2064. self.strategy_label = FCLabel('%s:' % _("Strategy"))
  2065. self.strategy_label.setToolTip(_("The strategy followed when encountering an exclusion area.\n"
  2066. "Can be:\n"
  2067. "- Over -> when encountering the area, the tool will go to a set height\n"
  2068. "- Around -> will avoid the exclusion area by going around the area"))
  2069. self.strategy_radio = RadioSet([{'label': _('Over'), 'value': 'over'},
  2070. {'label': _('Around'), 'value': 'around'}])
  2071. self.strategy_radio.setObjectName("e_area_strategy")
  2072. grid_a1.addWidget(self.strategy_label, 1, 0)
  2073. grid_a1.addWidget(self.strategy_radio, 1, 1)
  2074. # Over Z
  2075. self.over_z_label = FCLabel('%s:' % _("Over Z"))
  2076. self.over_z_label.setToolTip(_("The height Z to which the tool will rise in order to avoid\n"
  2077. "an interdiction area."))
  2078. self.over_z_entry = FCDoubleSpinner()
  2079. self.over_z_entry.set_range(0.000, 9999.9999)
  2080. self.over_z_entry.set_precision(self.decimals)
  2081. self.over_z_entry.setObjectName("e_area_overz")
  2082. grid_a1.addWidget(self.over_z_label, 2, 0)
  2083. grid_a1.addWidget(self.over_z_entry, 2, 1)
  2084. # Button Add Area
  2085. self.add_area_button = QtWidgets.QPushButton(_('Add area:'))
  2086. self.add_area_button.setToolTip(_("Add an Exclusion Area."))
  2087. # Area Selection shape
  2088. self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
  2089. {'label': _("Polygon"), 'value': 'polygon'}])
  2090. self.area_shape_radio.setToolTip(
  2091. _("The kind of selection shape used for area selection.")
  2092. )
  2093. self.area_shape_radio.setObjectName("e_area_shape")
  2094. grid_a1.addWidget(self.add_area_button, 4, 0)
  2095. grid_a1.addWidget(self.area_shape_radio, 4, 1)
  2096. h_lay_1 = QtWidgets.QHBoxLayout()
  2097. self.exclusion_box.addLayout(h_lay_1)
  2098. # Button Delete All Areas
  2099. self.delete_area_button = QtWidgets.QPushButton(_('Delete All'))
  2100. self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
  2101. # Button Delete Selected Areas
  2102. self.delete_sel_area_button = QtWidgets.QPushButton(_('Delete Selected'))
  2103. self.delete_sel_area_button.setToolTip(_("Delete all exclusion areas that are selected in the table."))
  2104. h_lay_1.addWidget(self.delete_area_button)
  2105. h_lay_1.addWidget(self.delete_sel_area_button)
  2106. self.ois_exclusion_exc = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
  2107. # -------------------------- EXCLUSION AREAS END -------------------------------------------------------------
  2108. # ------------------------------------------------------------------------------------------------------------
  2109. separator_line = QtWidgets.QFrame()
  2110. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  2111. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  2112. self.grid3.addWidget(separator_line, 25, 0, 1, 2)
  2113. # #################################################################
  2114. # ################# GRID LAYOUT 6 ###############################
  2115. # #################################################################
  2116. self.grid4 = QtWidgets.QGridLayout()
  2117. self.grid4.setColumnStretch(0, 0)
  2118. self.grid4.setColumnStretch(1, 1)
  2119. self.tools_box.addLayout(self.grid4)
  2120. self.generate_cnc_button = QtWidgets.QPushButton(_('Generate CNCJob object'))
  2121. self.generate_cnc_button.setIcon(QtGui.QIcon(self.app.resource_location + '/cnc16.png'))
  2122. self.generate_cnc_button.setToolTip(
  2123. _("Generate the CNC Job.\n"
  2124. "If milling then an additional Geometry object will be created.\n"
  2125. "Add / Select at least one tool in the tool-table.\n"
  2126. "Click the # header to select all, or Ctrl + LMB\n"
  2127. "for custom selection of tools.")
  2128. )
  2129. self.generate_cnc_button.setStyleSheet("""
  2130. QPushButton
  2131. {
  2132. font-weight: bold;
  2133. }
  2134. """)
  2135. self.grid4.addWidget(self.generate_cnc_button, 3, 0, 1, 3)
  2136. self.tools_box.addStretch()
  2137. # ## Reset Tool
  2138. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  2139. self.reset_button.setIcon(QtGui.QIcon(self.app.resource_location + '/reset32.png'))
  2140. self.reset_button.setToolTip(
  2141. _("Will reset the tool parameters.")
  2142. )
  2143. self.reset_button.setStyleSheet("""
  2144. QPushButton
  2145. {
  2146. font-weight: bold;
  2147. }
  2148. """)
  2149. self.tools_box.addWidget(self.reset_button)
  2150. # ############################ FINSIHED GUI ###################################
  2151. # #############################################################################
  2152. def confirmation_message(self, accepted, minval, maxval):
  2153. if accepted is False:
  2154. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  2155. self.decimals,
  2156. minval,
  2157. self.decimals,
  2158. maxval), False)
  2159. else:
  2160. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  2161. def confirmation_message_int(self, accepted, minval, maxval):
  2162. if accepted is False:
  2163. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  2164. (_("Edited value is out of range"), minval, maxval), False)
  2165. else:
  2166. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  2167. def distance(pt1, pt2):
  2168. return np.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
  2169. def distance_euclidian(x1, y1, x2, y2):
  2170. return np.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)