ToolMilling.py 96 KB

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