appDatabase.py 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526
  1. from PyQt5 import QtGui, QtCore, QtWidgets
  2. from appGUI.GUIElements import FCEntry, FCButton, FCDoubleSpinner, FCComboBox, FCCheckBox, FCSpinner, \
  3. FCTree, RadioSet, FCFileSaveDialog, FCLabel, FCComboBox2
  4. from camlib import to_dict
  5. import sys
  6. import json
  7. from copy import deepcopy
  8. from datetime import datetime
  9. import math
  10. import gettext
  11. import appTranslation as fcTranslate
  12. import builtins
  13. fcTranslate.apply_language('strings')
  14. if '_' not in builtins.__dict__:
  15. _ = gettext.gettext
  16. class ToolsDB2UI:
  17. def __init__(self, app, grid_layout):
  18. self.app = app
  19. self.decimals = self.app.decimals
  20. self.offset_item_options = ["Path", "In", "Out", "Custom"]
  21. self.type_item_options = [_("Iso"), _("Rough"), _("Finish")]
  22. self.tool_type_item_options = ["C1", "C2", "C3", "C4", "B", "V"]
  23. settings = QtCore.QSettings("Open Source", "FlatCAM")
  24. if settings.contains("machinist"):
  25. self.machinist_setting = settings.value('machinist', type=int)
  26. else:
  27. self.machinist_setting = 0
  28. self.g_lay = grid_layout
  29. tree_layout = QtWidgets.QVBoxLayout()
  30. self.g_lay.addLayout(tree_layout, 0, 0)
  31. self.tree_widget = FCTree(columns=2, header_hidden=False, protected_column=[0])
  32. self.tree_widget.setHeaderLabels([_("ID"), _("Tool Name")])
  33. self.tree_widget.setIndentation(0)
  34. self.tree_widget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
  35. self.tree_widget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
  36. # set alternating colors
  37. # self.tree_widget.setAlternatingRowColors(True)
  38. # p = QtGui.QPalette()
  39. # p.setColor(QtGui.QPalette.AlternateBase, QtGui.QColor(226, 237, 253) )
  40. # self.tree_widget.setPalette(p)
  41. self.tree_widget.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
  42. tree_layout.addWidget(self.tree_widget)
  43. param_hlay = QtWidgets.QHBoxLayout()
  44. param_area = QtWidgets.QScrollArea()
  45. param_widget = QtWidgets.QWidget()
  46. param_widget.setLayout(param_hlay)
  47. param_area.setWidget(param_widget)
  48. param_area.setWidgetResizable(True)
  49. self.g_lay.addWidget(param_area, 0, 1)
  50. # ###########################################################################
  51. # ############## The UI form ################################################
  52. # ###########################################################################
  53. # Tool description box
  54. self.tool_description_box = QtWidgets.QGroupBox()
  55. self.tool_description_box.setStyleSheet("""
  56. QGroupBox
  57. {
  58. font-size: 16px;
  59. font-weight: bold;
  60. }
  61. """)
  62. self.description_vlay = QtWidgets.QVBoxLayout()
  63. self.tool_description_box.setTitle(_("Tool Description"))
  64. self.tool_description_box.setMinimumWidth(250)
  65. # Milling box
  66. self.milling_box = QtWidgets.QGroupBox()
  67. self.milling_box.setStyleSheet("""
  68. QGroupBox
  69. {
  70. font-size: 16px;
  71. font-weight: bold;
  72. }
  73. """)
  74. self.milling_vlay = QtWidgets.QVBoxLayout()
  75. self.milling_box.setTitle(_("Milling Parameters"))
  76. self.milling_box.setMinimumWidth(250)
  77. # NCC TOOL BOX
  78. self.ncc_box = QtWidgets.QGroupBox()
  79. self.ncc_box.setStyleSheet("""
  80. QGroupBox
  81. {
  82. font-size: 16px;
  83. font-weight: bold;
  84. }
  85. """)
  86. self.ncc_vlay = QtWidgets.QVBoxLayout()
  87. self.ncc_box.setTitle(_("NCC Parameters"))
  88. self.ncc_box.setMinimumWidth(250)
  89. # PAINT TOOL BOX
  90. self.paint_box = QtWidgets.QGroupBox()
  91. self.paint_box.setStyleSheet("""
  92. QGroupBox
  93. {
  94. font-size: 16px;
  95. font-weight: bold;
  96. }
  97. """)
  98. self.paint_vlay = QtWidgets.QVBoxLayout()
  99. self.paint_box.setTitle(_("Paint Parameters"))
  100. self.paint_box.setMinimumWidth(250)
  101. # ISOLATION TOOL BOX
  102. self.iso_box = QtWidgets.QGroupBox()
  103. self.iso_box.setStyleSheet("""
  104. QGroupBox
  105. {
  106. font-size: 16px;
  107. font-weight: bold;
  108. }
  109. """)
  110. self.iso_vlay = QtWidgets.QVBoxLayout()
  111. self.iso_box.setTitle(_("Isolation Parameters"))
  112. self.iso_box.setMinimumWidth(250)
  113. # DRILLING TOOL BOX
  114. self.drill_box = QtWidgets.QGroupBox()
  115. self.drill_box.setStyleSheet("""
  116. QGroupBox
  117. {
  118. font-size: 16px;
  119. font-weight: bold;
  120. }
  121. """)
  122. self.drill_vlay = QtWidgets.QVBoxLayout()
  123. self.drill_box.setTitle(_("Drilling Parameters"))
  124. self.drill_box.setMinimumWidth(250)
  125. # CUTOUT TOOL BOX
  126. self.cutout_box = QtWidgets.QGroupBox()
  127. self.cutout_box.setStyleSheet("""
  128. QGroupBox
  129. {
  130. font-size: 16px;
  131. font-weight: bold;
  132. }
  133. """)
  134. self.cutout_vlay = QtWidgets.QVBoxLayout()
  135. self.cutout_box.setTitle(_("Cutout Parameters"))
  136. self.cutout_box.setMinimumWidth(250)
  137. # Layout Constructor
  138. self.tool_description_box.setLayout(self.description_vlay)
  139. self.milling_box.setLayout(self.milling_vlay)
  140. self.ncc_box.setLayout(self.ncc_vlay)
  141. self.paint_box.setLayout(self.paint_vlay)
  142. self.iso_box.setLayout(self.iso_vlay)
  143. self.drill_box.setLayout(self.drill_vlay)
  144. self.cutout_box.setLayout(self.cutout_vlay)
  145. tools_vlay = QtWidgets.QVBoxLayout()
  146. tools_vlay.addWidget(self.iso_box)
  147. tools_vlay.addWidget(self.paint_box)
  148. tools_vlay.addWidget(self.ncc_box)
  149. tools_vlay.addWidget(self.cutout_box)
  150. tools_vlay.addStretch()
  151. descript_vlay = QtWidgets.QVBoxLayout()
  152. descript_vlay.addWidget(self.tool_description_box)
  153. descript_vlay.addLayout(tools_vlay)
  154. descript_vlay.addStretch()
  155. mill_vlay = QtWidgets.QVBoxLayout()
  156. mill_vlay.addWidget(self.milling_box)
  157. mill_vlay.addStretch()
  158. drilling_vlay = QtWidgets.QVBoxLayout()
  159. drilling_vlay.addWidget(self.drill_box)
  160. param_hlay.addLayout(descript_vlay)
  161. param_hlay.addLayout(drilling_vlay)
  162. param_hlay.addLayout(tools_vlay)
  163. # always visible, always to be included last
  164. param_hlay.addLayout(mill_vlay)
  165. param_hlay.addStretch()
  166. # ###########################################################################
  167. # ################ Tool UI form #############################################
  168. # ###########################################################################
  169. self.grid_tool = QtWidgets.QGridLayout()
  170. self.description_vlay.addLayout(self.grid_tool)
  171. self.grid_tool.setColumnStretch(0, 0)
  172. self.grid_tool.setColumnStretch(1, 1)
  173. self.description_vlay.addStretch()
  174. # Tool Name
  175. self.name_label = FCLabel('<span style="color:red;"><b>%s:</b></span>' % _('Name'))
  176. self.name_label.setToolTip(
  177. _("Tool name.\n"
  178. "This is not used in the app, it's function\n"
  179. "is to serve as a note for the user."))
  180. self.name_entry = FCEntry()
  181. self.name_entry.setObjectName('gdb_name')
  182. self.grid_tool.addWidget(self.name_label, 0, 0)
  183. self.grid_tool.addWidget(self.name_entry, 0, 1)
  184. # Tool Dia
  185. self.dia_label = FCLabel('%s:' % _('Diameter'))
  186. self.dia_label.setToolTip(
  187. _("Tool Diameter."))
  188. self.dia_entry = FCDoubleSpinner()
  189. self.dia_entry.set_range(-9999.9999, 9999.9999)
  190. self.dia_entry.set_precision(self.decimals)
  191. self.dia_entry.setObjectName('gdb_dia')
  192. self.grid_tool.addWidget(self.dia_label, 1, 0)
  193. self.grid_tool.addWidget(self.dia_entry, 1, 1)
  194. # Tool Tolerance
  195. self.tol_label = FCLabel("<b>%s:</b>" % _("Diameter Tolerance"))
  196. self.tol_label.setToolTip(
  197. _("Tool tolerance. This tool will be used if the desired tool diameter\n"
  198. "is within the tolerance specified here.")
  199. )
  200. self.grid_tool.addWidget(self.tol_label, 2, 0, 1, 2)
  201. # Tolerance Min Limit
  202. self.min_limit_label = FCLabel('%s:' % _("Min"))
  203. self.min_limit_label.setToolTip(
  204. _("Set the tool tolerance minimum.")
  205. )
  206. self.tol_min_entry = FCDoubleSpinner(callback=self.confirmation_message)
  207. self.tol_min_entry.set_precision(self.decimals)
  208. self.tol_min_entry.set_range(0, 9999.9999)
  209. self.tol_min_entry.setSingleStep(0.1)
  210. self.tol_min_entry.setObjectName("gdb_tol_min")
  211. self.grid_tool.addWidget(self.min_limit_label, 4, 0)
  212. self.grid_tool.addWidget(self.tol_min_entry, 4, 1)
  213. # Tolerance Min Limit
  214. self.max_limit_label = FCLabel('%s:' % _("Max"))
  215. self.max_limit_label.setToolTip(
  216. _("Set the tool tolerance maximum.")
  217. )
  218. self.tol_max_entry = FCDoubleSpinner(callback=self.confirmation_message)
  219. self.tol_max_entry.set_precision(self.decimals)
  220. self.tol_max_entry.set_range(0, 9999.9999)
  221. self.tol_max_entry.setSingleStep(0.1)
  222. self.tol_max_entry.setObjectName("gdb_tol_max")
  223. self.grid_tool.addWidget(self.max_limit_label, 6, 0)
  224. self.grid_tool.addWidget(self.tol_max_entry, 6, 1)
  225. # Tool Object Type
  226. self.tool_op_label = FCLabel('<b>%s:</b>' % _('Operation'))
  227. self.tool_op_label.setToolTip(
  228. _("The kind of Application Tool where this tool is to be used."))
  229. self.tool_op_combo = FCComboBox2()
  230. self.tool_op_combo.addItems(
  231. [_("General"), _("Milling"), _("Drilling"), _('Isolation'), _('Paint'), _('NCC'), _('Cutout')])
  232. self.tool_op_combo.setObjectName('gdb_tool_target')
  233. self.grid_tool.addWidget(self.tool_op_label, 8, 0)
  234. self.grid_tool.addWidget(self.tool_op_combo, 8, 1)
  235. # ###########################################################################
  236. # ############### MILLING UI form ###########################################
  237. # ###########################################################################
  238. self.grid0 = QtWidgets.QGridLayout()
  239. self.milling_vlay.addLayout(self.grid0)
  240. self.grid0.setColumnStretch(0, 0)
  241. self.grid0.setColumnStretch(1, 1)
  242. self.milling_vlay.addStretch()
  243. # Tool Shape
  244. self.shape_label = FCLabel('%s:' % _('Shape'))
  245. self.shape_label.setToolTip(
  246. _("Tool Shape. \n"
  247. "Can be:\n"
  248. "C1 ... C4 = circular tool with x flutes\n"
  249. "B = ball tip milling tool\n"
  250. "V = v-shape milling tool"))
  251. self.mill_shape_combo = FCComboBox()
  252. self.mill_shape_combo.addItems(self.tool_type_item_options)
  253. self.mill_shape_combo.setObjectName('gdb_shape')
  254. self.grid0.addWidget(self.shape_label, 2, 0)
  255. self.grid0.addWidget(self.mill_shape_combo, 2, 1)
  256. # V-Dia
  257. self.vdia_label = FCLabel('%s:' % _("V-Dia"))
  258. self.vdia_label.setToolTip(
  259. _("V-Dia.\n"
  260. "Diameter of the tip for V-Shape Tools."))
  261. self.mill_vdia_entry = FCDoubleSpinner()
  262. self.mill_vdia_entry.set_range(0.0000, 9999.9999)
  263. self.mill_vdia_entry.set_precision(self.decimals)
  264. self.mill_vdia_entry.setObjectName('gdb_vdia')
  265. self.grid0.addWidget(self.vdia_label, 4, 0)
  266. self.grid0.addWidget(self.mill_vdia_entry, 4, 1)
  267. # V-Angle
  268. self.vangle_label = FCLabel('%s:' % _("V-Angle"))
  269. self.vangle_label.setToolTip(
  270. _("V-Agle.\n"
  271. "Angle at the tip for the V-Shape Tools."))
  272. self.mill_vangle_entry = FCDoubleSpinner()
  273. self.mill_vangle_entry.set_range(-360.0, 360.0)
  274. self.mill_vangle_entry.set_precision(self.decimals)
  275. self.mill_vangle_entry.setObjectName('gdb_vangle')
  276. self.grid0.addWidget(self.vangle_label, 6, 0)
  277. self.grid0.addWidget(self.mill_vangle_entry, 6, 1)
  278. separator_line = QtWidgets.QFrame()
  279. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  280. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  281. self.grid0.addWidget(separator_line, 8, 0, 1, 2)
  282. # Tool Type
  283. self.type_label = FCLabel('%s:' % _("Tool Type"))
  284. self.type_label.setToolTip(
  285. _("Tool Type.\n"
  286. "Can be:\n"
  287. "Iso = isolation cut\n"
  288. "Rough = rough cut, low feedrate, multiple passes\n"
  289. "Finish = finishing cut, high feedrate"))
  290. self.mill_type_combo = FCComboBox()
  291. self.mill_type_combo.addItems(self.type_item_options)
  292. self.mill_type_combo.setObjectName('gdb_type')
  293. self.grid0.addWidget(self.type_label, 10, 0)
  294. self.grid0.addWidget(self.mill_type_combo, 10, 1)
  295. # Tool Offset
  296. self.tooloffset_label = FCLabel('%s:' % _('Tool Offset'))
  297. self.tooloffset_label.setToolTip(
  298. _("Tool Offset.\n"
  299. "Can be of a few types:\n"
  300. "Path = zero offset\n"
  301. "In = offset inside by half of tool diameter\n"
  302. "Out = offset outside by half of tool diameter\n"
  303. "Custom = custom offset using the Custom Offset value"))
  304. self.mill_tooloffset_combo = FCComboBox()
  305. self.mill_tooloffset_combo.addItems(self.offset_item_options)
  306. self.mill_tooloffset_combo.setObjectName('gdb_tool_offset')
  307. self.grid0.addWidget(self.tooloffset_label, 12, 0)
  308. self.grid0.addWidget(self.mill_tooloffset_combo, 12, 1)
  309. # Custom Offset
  310. self.custom_offset_label = FCLabel('%s:' % _("Custom Offset"))
  311. self.custom_offset_label.setToolTip(
  312. _("Custom Offset.\n"
  313. "A value to be used as offset from the current path."))
  314. self.mill_custom_offset_entry = FCDoubleSpinner()
  315. self.mill_custom_offset_entry.set_range(-9999.9999, 9999.9999)
  316. self.mill_custom_offset_entry.set_precision(self.decimals)
  317. self.mill_custom_offset_entry.setObjectName('gdb_custom_offset')
  318. self.grid0.addWidget(self.custom_offset_label, 14, 0)
  319. self.grid0.addWidget(self.mill_custom_offset_entry, 14, 1)
  320. separator_line = QtWidgets.QFrame()
  321. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  322. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  323. self.grid0.addWidget(separator_line, 16, 0, 1, 2)
  324. # Cut Z
  325. self.cutz_label = FCLabel('%s:' % _("Cut Z"))
  326. self.cutz_label.setToolTip(
  327. _("Cutting Depth.\n"
  328. "The depth at which to cut into material."))
  329. self.mill_cutz_entry = FCDoubleSpinner()
  330. self.mill_cutz_entry.set_range(-9999.9999, 9999.9999)
  331. self.mill_cutz_entry.set_precision(self.decimals)
  332. self.mill_cutz_entry.setObjectName('gdb_cutz')
  333. self.grid0.addWidget(self.cutz_label, 18, 0)
  334. self.grid0.addWidget(self.mill_cutz_entry, 18, 1)
  335. # Multi Depth
  336. self.multidepth_label = FCLabel('%s:' % _("MultiDepth"))
  337. self.multidepth_label.setToolTip(
  338. _("Multi Depth.\n"
  339. "Selecting this will allow cutting in multiple passes,\n"
  340. "each pass adding a DPP parameter depth."))
  341. self.mill_multidepth_cb = FCCheckBox()
  342. self.mill_multidepth_cb.setObjectName('gdb_multidepth')
  343. self.grid0.addWidget(self.multidepth_label, 20, 0)
  344. self.grid0.addWidget(self.mill_multidepth_cb, 20, 1)
  345. # Depth Per Pass
  346. self.dpp_label = FCLabel('%s:' % _("DPP"))
  347. self.dpp_label.setToolTip(
  348. _("DPP. Depth per Pass.\n"
  349. "The value used to cut into material on each pass."))
  350. self.mill_multidepth_entry = FCDoubleSpinner()
  351. self.mill_multidepth_entry.set_range(-9999.9999, 9999.9999)
  352. self.mill_multidepth_entry.set_precision(self.decimals)
  353. self.mill_multidepth_entry.setObjectName('gdb_multidepth_entry')
  354. self.grid0.addWidget(self.dpp_label, 22, 0)
  355. self.grid0.addWidget(self.mill_multidepth_entry, 22, 1)
  356. # Travel Z
  357. self.travelz_label = FCLabel('%s:' % _("Travel Z"))
  358. self.travelz_label.setToolTip(
  359. _("Clearance Height.\n"
  360. "Height at which the milling bit will travel between cuts,\n"
  361. "above the surface of the material, avoiding all fixtures."))
  362. self.mill_travelz_entry = FCDoubleSpinner()
  363. self.mill_travelz_entry.set_range(-9999.9999, 9999.9999)
  364. self.mill_travelz_entry.set_precision(self.decimals)
  365. self.mill_travelz_entry.setObjectName('gdb_travelz')
  366. self.grid0.addWidget(self.travelz_label, 24, 0)
  367. self.grid0.addWidget(self.mill_travelz_entry, 24, 1)
  368. # Extra Cut
  369. self.ecut_label = FCLabel('%s:' % _("ExtraCut"))
  370. self.ecut_label.setToolTip(
  371. _("Extra Cut.\n"
  372. "If checked, after a isolation is finished an extra cut\n"
  373. "will be added where the start and end of isolation meet\n"
  374. "such as that this point is covered by this extra cut to\n"
  375. "ensure a complete isolation."))
  376. self.mill_ecut_cb = FCCheckBox()
  377. self.mill_ecut_cb.setObjectName('gdb_ecut')
  378. self.grid0.addWidget(self.ecut_label, 26, 0)
  379. self.grid0.addWidget(self.mill_ecut_cb, 26, 1)
  380. # Extra Cut Length
  381. self.ecut_length_label = FCLabel('%s:' % _("E-Cut Length"))
  382. self.ecut_length_label.setToolTip(
  383. _("Extra Cut length.\n"
  384. "If checked, after a isolation is finished an extra cut\n"
  385. "will be added where the start and end of isolation meet\n"
  386. "such as that this point is covered by this extra cut to\n"
  387. "ensure a complete isolation. This is the length of\n"
  388. "the extra cut."))
  389. self.mill_ecut_length_entry = FCDoubleSpinner()
  390. self.mill_ecut_length_entry.set_range(0.0000, 9999.9999)
  391. self.mill_ecut_length_entry.set_precision(self.decimals)
  392. self.mill_ecut_length_entry.setObjectName('gdb_ecut_length')
  393. self.grid0.addWidget(self.ecut_length_label, 28, 0)
  394. self.grid0.addWidget(self.mill_ecut_length_entry, 28, 1)
  395. separator_line = QtWidgets.QFrame()
  396. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  397. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  398. self.grid0.addWidget(separator_line, 30, 0, 1, 2)
  399. # Feedrate X-Y
  400. self.frxy_label = FCLabel('%s:' % _("Feedrate X-Y"))
  401. self.frxy_label.setToolTip(
  402. _("Feedrate X-Y. Feedrate\n"
  403. "The speed on XY plane used while cutting into material."))
  404. self.mill_frxy_entry = FCDoubleSpinner()
  405. self.mill_frxy_entry.set_range(-999999.9999, 999999.9999)
  406. self.mill_frxy_entry.set_precision(self.decimals)
  407. self.mill_frxy_entry.setObjectName('gdb_frxy')
  408. self.grid0.addWidget(self.frxy_label, 32, 0)
  409. self.grid0.addWidget(self.mill_frxy_entry, 32, 1)
  410. # Feedrate Z
  411. self.frz_label = FCLabel('%s:' % _("Feedrate Z"))
  412. self.frz_label.setToolTip(
  413. _("Feedrate Z\n"
  414. "The speed on Z plane."))
  415. self.mill_frz_entry = FCDoubleSpinner()
  416. self.mill_frz_entry.set_range(-999999.9999, 999999.9999)
  417. self.mill_frz_entry.set_precision(self.decimals)
  418. self.mill_frz_entry.setObjectName('gdb_frz')
  419. self.grid0.addWidget(self.frz_label, 34, 0)
  420. self.grid0.addWidget(self.mill_frz_entry, 34, 1)
  421. # Feedrate Rapids
  422. self.frapids_label = FCLabel('%s:' % _("FR Rapids"))
  423. self.frapids_label.setToolTip(
  424. _("FR Rapids. Feedrate Rapids\n"
  425. "Speed used while moving as fast as possible.\n"
  426. "This is used only by some devices that can't use\n"
  427. "the G0 g-code command. Mostly 3D printers."))
  428. self.mill_frapids_entry = FCDoubleSpinner()
  429. self.mill_frapids_entry.set_range(0.0000, 9999.9999)
  430. self.mill_frapids_entry.set_precision(self.decimals)
  431. self.mill_frapids_entry.setObjectName('gdb_frapids')
  432. self.grid0.addWidget(self.frapids_label, 36, 0)
  433. self.grid0.addWidget(self.mill_frapids_entry, 36, 1)
  434. separator_line = QtWidgets.QFrame()
  435. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  436. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  437. self.grid0.addWidget(separator_line, 38, 0, 1, 2)
  438. # Spindle Spped
  439. self.spindle_label = FCLabel('%s:' % _("Spindle Speed"))
  440. self.spindle_label.setToolTip(
  441. _("Spindle Speed.\n"
  442. "If it's left empty it will not be used.\n"
  443. "The speed of the spindle in RPM."))
  444. self.mill_spindle_entry = FCDoubleSpinner()
  445. self.mill_spindle_entry.set_range(-999999.9999, 999999.9999)
  446. self.mill_spindle_entry.set_precision(self.decimals)
  447. self.mill_spindle_entry.setObjectName('gdb_spindle')
  448. self.grid0.addWidget(self.spindle_label, 40, 0)
  449. self.grid0.addWidget(self.mill_spindle_entry, 40, 1)
  450. # Dwell
  451. self.dwell_label = FCLabel('%s:' % _("Dwell"))
  452. self.dwell_label.setToolTip(
  453. _("Dwell.\n"
  454. "Check this if a delay is needed to allow\n"
  455. "the spindle motor to reach its set speed."))
  456. self.mill_dwell_cb = FCCheckBox()
  457. self.mill_dwell_cb.setObjectName('gdb_dwell')
  458. self.grid0.addWidget(self.dwell_label, 42, 0)
  459. self.grid0.addWidget(self.mill_dwell_cb, 42, 1)
  460. # Dwell Time
  461. self.dwelltime_label = FCLabel('%s:' % _("Dwelltime"))
  462. self.dwelltime_label.setToolTip(
  463. _("Dwell Time.\n"
  464. "A delay used to allow the motor spindle reach its set speed."))
  465. self.mill_dwelltime_entry = FCDoubleSpinner()
  466. self.mill_dwelltime_entry.set_range(0.0000, 9999.9999)
  467. self.mill_dwelltime_entry.set_precision(self.decimals)
  468. self.mill_dwelltime_entry.setObjectName('gdb_dwelltime')
  469. self.grid0.addWidget(self.dwelltime_label, 44, 0)
  470. self.grid0.addWidget(self.mill_dwelltime_entry, 44, 1)
  471. # ###########################################################################
  472. # ############### NCC UI form ###############################################
  473. # ###########################################################################
  474. self.grid2 = QtWidgets.QGridLayout()
  475. self.ncc_vlay.addLayout(self.grid2)
  476. self.grid2.setColumnStretch(0, 0)
  477. self.grid2.setColumnStretch(1, 1)
  478. self.ncc_vlay.addStretch()
  479. # Operation
  480. op_label = FCLabel('%s:' % _('Operation'))
  481. op_label.setToolTip(
  482. _("The 'Operation' can be:\n"
  483. "- Isolation -> will ensure that the non-copper clearing is always complete.\n"
  484. "If it's not successful then the non-copper clearing will fail, too.\n"
  485. "- Clear -> the regular non-copper clearing.")
  486. )
  487. self.ncc_op_radio = RadioSet([
  488. {"label": _("Clear"), "value": "clear"},
  489. {"label": _("Isolation"), "value": "iso"}
  490. ], orientation='horizontal', stretch=False)
  491. self.ncc_op_radio.setObjectName("gdb_n_operation")
  492. self.grid2.addWidget(op_label, 13, 0)
  493. self.grid2.addWidget(self.ncc_op_radio, 13, 1)
  494. # Milling Type Radio Button
  495. self.milling_type_label = FCLabel('%s:' % _('Milling Type'))
  496. self.milling_type_label.setToolTip(
  497. _("Milling type when the selected tool is of type: 'iso_op':\n"
  498. "- climb / best for precision milling and to reduce tool usage\n"
  499. "- conventional / useful when there is no backlash compensation")
  500. )
  501. self.ncc_milling_type_radio = RadioSet([{'label': _('Climb'), 'value': 'cl'},
  502. {'label': _('Conventional'), 'value': 'cv'}])
  503. self.ncc_milling_type_radio.setToolTip(
  504. _("Milling type when the selected tool is of type: 'iso_op':\n"
  505. "- climb / best for precision milling and to reduce tool usage\n"
  506. "- conventional / useful when there is no backlash compensation")
  507. )
  508. self.ncc_milling_type_radio.setObjectName("gdb_n_milling_type")
  509. self.grid2.addWidget(self.milling_type_label, 14, 0)
  510. self.grid2.addWidget(self.ncc_milling_type_radio, 14, 1)
  511. # Overlap Entry
  512. nccoverlabel = FCLabel('%s:' % _('Overlap'))
  513. nccoverlabel.setToolTip(
  514. _("How much (percentage) of the tool width to overlap each tool pass.\n"
  515. "Adjust the value starting with lower values\n"
  516. "and increasing it if areas that should be cleared are still \n"
  517. "not cleared.\n"
  518. "Lower values = faster processing, faster execution on CNC.\n"
  519. "Higher values = slow processing and slow execution on CNC\n"
  520. "due of too many paths.")
  521. )
  522. self.ncc_overlap_entry = FCDoubleSpinner(suffix='%')
  523. self.ncc_overlap_entry.set_precision(self.decimals)
  524. self.ncc_overlap_entry.setWrapping(True)
  525. self.ncc_overlap_entry.setRange(0.000, 99.9999)
  526. self.ncc_overlap_entry.setSingleStep(0.1)
  527. self.ncc_overlap_entry.setObjectName("gdb_n_overlap")
  528. self.grid2.addWidget(nccoverlabel, 15, 0)
  529. self.grid2.addWidget(self.ncc_overlap_entry, 15, 1)
  530. # Margin
  531. nccmarginlabel = FCLabel('%s:' % _('Margin'))
  532. nccmarginlabel.setToolTip(
  533. _("Bounding box margin.")
  534. )
  535. self.ncc_margin_entry = FCDoubleSpinner()
  536. self.ncc_margin_entry.set_precision(self.decimals)
  537. self.ncc_margin_entry.set_range(-9999.9999, 9999.9999)
  538. self.ncc_margin_entry.setObjectName("gdb_n_margin")
  539. self.grid2.addWidget(nccmarginlabel, 16, 0)
  540. self.grid2.addWidget(self.ncc_margin_entry, 16, 1)
  541. # Method
  542. methodlabel = FCLabel('%s:' % _('Method'))
  543. methodlabel.setToolTip(
  544. _("Algorithm for copper clearing:\n"
  545. "- Standard: Fixed step inwards.\n"
  546. "- Seed-based: Outwards from seed.\n"
  547. "- Line-based: Parallel lines.")
  548. )
  549. self.ncc_method_combo = FCComboBox2()
  550. self.ncc_method_combo.addItems(
  551. [_("Standard"), _("Seed"), _("Lines"), _("Combo")]
  552. )
  553. self.ncc_method_combo.setObjectName("gdb_n_method")
  554. self.grid2.addWidget(methodlabel, 17, 0)
  555. self.grid2.addWidget(self.ncc_method_combo, 17, 1)
  556. # Connect lines
  557. self.ncc_connect_cb = FCCheckBox('%s' % _("Connect"))
  558. self.ncc_connect_cb.setObjectName("gdb_n_connect")
  559. self.ncc_connect_cb.setToolTip(
  560. _("Draw lines between resulting\n"
  561. "segments to minimize tool lifts.")
  562. )
  563. self.grid2.addWidget(self.ncc_connect_cb, 18, 0)
  564. # Contour
  565. self.ncc_contour_cb = FCCheckBox('%s' % _("Contour"))
  566. self.ncc_contour_cb.setObjectName("gdb_n_contour")
  567. self.ncc_contour_cb.setToolTip(
  568. _("Cut around the perimeter of the polygon\n"
  569. "to trim rough edges.")
  570. )
  571. self.grid2.addWidget(self.ncc_contour_cb, 18, 1)
  572. # ## NCC Offset choice
  573. self.ncc_choice_offset_cb = FCCheckBox('%s' % _("Offset"))
  574. self.ncc_choice_offset_cb.setObjectName("gdb_n_offset")
  575. self.ncc_choice_offset_cb.setToolTip(
  576. _("If used, it will add an offset to the copper features.\n"
  577. "The copper clearing will finish to a distance\n"
  578. "from the copper features.\n"
  579. "The value can be between 0 and 10 FlatCAM units.")
  580. )
  581. self.grid2.addWidget(self.ncc_choice_offset_cb, 19, 0)
  582. # ## NCC Offset Entry
  583. self.ncc_offset_spinner = FCDoubleSpinner()
  584. self.ncc_offset_spinner.set_range(0.00, 10.00)
  585. self.ncc_offset_spinner.set_precision(4)
  586. self.ncc_offset_spinner.setWrapping(True)
  587. self.ncc_offset_spinner.setObjectName("gdb_n_offset_value")
  588. units = self.app.defaults['units'].upper()
  589. if units == 'MM':
  590. self.ncc_offset_spinner.setSingleStep(0.1)
  591. else:
  592. self.ncc_offset_spinner.setSingleStep(0.01)
  593. self.grid2.addWidget(self.ncc_offset_spinner, 19, 1)
  594. # ###########################################################################
  595. # ############### Paint UI form #############################################
  596. # ###########################################################################
  597. self.grid3 = QtWidgets.QGridLayout()
  598. self.paint_vlay.addLayout(self.grid3)
  599. self.grid3.setColumnStretch(0, 0)
  600. self.grid3.setColumnStretch(1, 1)
  601. self.paint_vlay.addStretch()
  602. # Overlap
  603. ovlabel = FCLabel('%s:' % _('Overlap'))
  604. ovlabel.setToolTip(
  605. _("How much (percentage) of the tool width to overlap each tool pass.\n"
  606. "Adjust the value starting with lower values\n"
  607. "and increasing it if areas that should be painted are still \n"
  608. "not painted.\n"
  609. "Lower values = faster processing, faster execution on CNC.\n"
  610. "Higher values = slow processing and slow execution on CNC\n"
  611. "due of too many paths.")
  612. )
  613. self.paint_overlap_entry = FCDoubleSpinner(suffix='%')
  614. self.paint_overlap_entry.set_precision(3)
  615. self.paint_overlap_entry.setWrapping(True)
  616. self.paint_overlap_entry.setRange(0.0000, 99.9999)
  617. self.paint_overlap_entry.setSingleStep(0.1)
  618. self.paint_overlap_entry.setObjectName('gdb_p_overlap')
  619. self.grid3.addWidget(ovlabel, 1, 0)
  620. self.grid3.addWidget(self.paint_overlap_entry, 1, 1)
  621. # Margin
  622. marginlabel = FCLabel('%s:' % _('Offset'))
  623. marginlabel.setToolTip(
  624. _("Distance by which to avoid\n"
  625. "the edges of the polygon to\n"
  626. "be painted.")
  627. )
  628. self.paint_offset_entry = FCDoubleSpinner()
  629. self.paint_offset_entry.set_precision(self.decimals)
  630. self.paint_offset_entry.set_range(-9999.9999, 9999.9999)
  631. self.paint_offset_entry.setObjectName('gdb_p_offset')
  632. self.grid3.addWidget(marginlabel, 2, 0)
  633. self.grid3.addWidget(self.paint_offset_entry, 2, 1)
  634. # Method
  635. methodlabel = FCLabel('%s:' % _('Method'))
  636. methodlabel.setToolTip(
  637. _("Algorithm for painting:\n"
  638. "- Standard: Fixed step inwards.\n"
  639. "- Seed-based: Outwards from seed.\n"
  640. "- Line-based: Parallel lines.\n"
  641. "- Laser-lines: Active only for Gerber objects.\n"
  642. "Will create lines that follow the traces.\n"
  643. "- Combo: In case of failure a new method will be picked from the above\n"
  644. "in the order specified.")
  645. )
  646. self.paint_method_combo = FCComboBox2()
  647. self.paint_method_combo.addItems(
  648. [_("Standard"), _("Seed"), _("Lines"), _("Laser_lines"), _("Combo")]
  649. )
  650. idx = self.paint_method_combo.findText(_("Laser_lines"))
  651. self.paint_method_combo.model().item(idx).setEnabled(False)
  652. self.paint_method_combo.setObjectName('gdb_p_method')
  653. self.grid3.addWidget(methodlabel, 7, 0)
  654. self.grid3.addWidget(self.paint_method_combo, 7, 1)
  655. # Connect lines
  656. self.path_connect_cb = FCCheckBox('%s' % _("Connect"))
  657. self.path_connect_cb.setObjectName('gdb_p_connect')
  658. self.path_connect_cb.setToolTip(
  659. _("Draw lines between resulting\n"
  660. "segments to minimize tool lifts.")
  661. )
  662. self.paint_contour_cb = FCCheckBox('%s' % _("Contour"))
  663. self.paint_contour_cb.setObjectName('gdb_p_contour')
  664. self.paint_contour_cb.setToolTip(
  665. _("Cut around the perimeter of the polygon\n"
  666. "to trim rough edges.")
  667. )
  668. self.grid3.addWidget(self.path_connect_cb, 10, 0)
  669. self.grid3.addWidget(self.paint_contour_cb, 10, 1)
  670. # ###########################################################################
  671. # ############### Isolation UI form #########################################
  672. # ###########################################################################
  673. self.grid4 = QtWidgets.QGridLayout()
  674. self.iso_vlay.addLayout(self.grid4)
  675. self.grid4.setColumnStretch(0, 0)
  676. self.grid4.setColumnStretch(1, 1)
  677. self.iso_vlay.addStretch()
  678. # Passes
  679. passlabel = FCLabel('%s:' % _('Passes'))
  680. passlabel.setToolTip(
  681. _("Width of the isolation gap in\n"
  682. "number (integer) of tool widths.")
  683. )
  684. self.iso_passes_entry = FCSpinner()
  685. self.iso_passes_entry.set_range(1, 999)
  686. self.iso_passes_entry.setObjectName("gdb_i_passes")
  687. self.grid4.addWidget(passlabel, 0, 0)
  688. self.grid4.addWidget(self.iso_passes_entry, 0, 1)
  689. # Overlap Entry
  690. overlabel = FCLabel('%s:' % _('Overlap'))
  691. overlabel.setToolTip(
  692. _("How much (percentage) of the tool width to overlap each tool pass.")
  693. )
  694. self.iso_overlap_entry = FCDoubleSpinner(suffix='%')
  695. self.iso_overlap_entry.set_precision(self.decimals)
  696. self.iso_overlap_entry.setWrapping(True)
  697. self.iso_overlap_entry.set_range(0.0000, 99.9999)
  698. self.iso_overlap_entry.setSingleStep(0.1)
  699. self.iso_overlap_entry.setObjectName("gdb_i_overlap")
  700. self.grid4.addWidget(overlabel, 2, 0)
  701. self.grid4.addWidget(self.iso_overlap_entry, 2, 1)
  702. # Milling Type Radio Button
  703. self.iso_milling_type_label = FCLabel('%s:' % _('Milling Type'))
  704. self.iso_milling_type_label.setToolTip(
  705. _("Milling type when the selected tool is of type: 'iso_op':\n"
  706. "- climb / best for precision milling and to reduce tool usage\n"
  707. "- conventional / useful when there is no backlash compensation")
  708. )
  709. self.iso_milling_type_radio = RadioSet([{'label': _('Climb'), 'value': 'cl'},
  710. {'label': _('Conventional'), 'value': 'cv'}])
  711. self.iso_milling_type_radio.setToolTip(
  712. _("Milling type when the selected tool is of type: 'iso_op':\n"
  713. "- climb / best for precision milling and to reduce tool usage\n"
  714. "- conventional / useful when there is no backlash compensation")
  715. )
  716. self.iso_milling_type_radio.setObjectName("gdb_i_milling_type")
  717. self.grid4.addWidget(self.iso_milling_type_label, 4, 0)
  718. self.grid4.addWidget(self.iso_milling_type_radio, 4, 1)
  719. # Follow
  720. self.follow_label = FCLabel('%s:' % _('Follow'))
  721. self.follow_label.setToolTip(
  722. _("Generate a 'Follow' geometry.\n"
  723. "This means that it will cut through\n"
  724. "the middle of the trace.")
  725. )
  726. self.iso_follow_cb = FCCheckBox()
  727. self.iso_follow_cb.setToolTip(_("Generate a 'Follow' geometry.\n"
  728. "This means that it will cut through\n"
  729. "the middle of the trace."))
  730. self.iso_follow_cb.setObjectName("gdb_i_follow")
  731. self.grid4.addWidget(self.follow_label, 6, 0)
  732. self.grid4.addWidget(self.iso_follow_cb, 6, 1)
  733. # Isolation Type
  734. self.iso_type_label = FCLabel('%s:' % _('Isolation Type'))
  735. self.iso_type_label.setToolTip(
  736. _("Choose how the isolation will be executed:\n"
  737. "- 'Full' -> complete isolation of polygons\n"
  738. "- 'Ext' -> will isolate only on the outside\n"
  739. "- 'Int' -> will isolate only on the inside\n"
  740. "'Exterior' isolation is almost always possible\n"
  741. "(with the right tool) but 'Interior'\n"
  742. "isolation can be done only when there is an opening\n"
  743. "inside of the polygon (e.g polygon is a 'doughnut' shape).")
  744. )
  745. self.iso_type_radio = RadioSet([{'label': _('Full'), 'value': 'full'},
  746. {'label': _('Ext'), 'value': 'ext'},
  747. {'label': _('Int'), 'value': 'int'}])
  748. self.iso_type_radio.setObjectName("gdb_i_iso_type")
  749. self.grid4.addWidget(self.iso_type_label, 8, 0)
  750. self.grid4.addWidget(self.iso_type_radio, 8, 1)
  751. # ###########################################################################
  752. # ################ DRILLING UI form #########################################
  753. # ###########################################################################
  754. self.grid5 = QtWidgets.QGridLayout()
  755. self.drill_vlay.addLayout(self.grid5)
  756. self.grid5.setColumnStretch(0, 0)
  757. self.grid5.setColumnStretch(1, 1)
  758. self.drill_vlay.addStretch()
  759. # Cut Z
  760. self.cutzlabel = FCLabel('%s:' % _('Cut Z'))
  761. self.cutzlabel.setToolTip(
  762. _("Drill depth (negative)\n"
  763. "below the copper surface.")
  764. )
  765. self.drill_cutz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  766. self.drill_cutz_entry.set_precision(self.decimals)
  767. if self.machinist_setting == 0:
  768. self.drill_cutz_entry.set_range(-9999.9999, 0.0000)
  769. else:
  770. self.drill_cutz_entry.set_range(-9999.9999, 9999.9999)
  771. self.drill_cutz_entry.setSingleStep(0.1)
  772. self.drill_cutz_entry.setObjectName("gdb_e_cutz")
  773. self.grid5.addWidget(self.cutzlabel, 4, 0)
  774. self.grid5.addWidget(self.drill_cutz_entry, 4, 1)
  775. # Tool Offset
  776. self.tool_offset_label = FCLabel('%s:' % _('Offset Z'))
  777. self.tool_offset_label.setToolTip(
  778. _("Some drill bits (the larger ones) need to drill deeper\n"
  779. "to create the desired exit hole diameter due of the tip shape.\n"
  780. "The value here can compensate the Cut Z parameter.")
  781. )
  782. self.drill_offset_entry = FCDoubleSpinner(callback=self.confirmation_message)
  783. self.drill_offset_entry.set_precision(self.decimals)
  784. self.drill_offset_entry.set_range(-9999.9999, 9999.9999)
  785. self.drill_offset_entry.setObjectName("gdb_e_offset")
  786. self.grid5.addWidget(self.tool_offset_label, 6, 0)
  787. self.grid5.addWidget(self.drill_offset_entry, 6, 1)
  788. # Multi-Depth
  789. self.multidepth_drill_label = FCLabel('%s:' % _("MultiDepth"))
  790. self.multidepth_drill_label.setToolTip(
  791. _(
  792. "Use multiple passes to limit\n"
  793. "the cut depth in each pass. Will\n"
  794. "cut multiple times until Cut Z is\n"
  795. "reached."
  796. )
  797. )
  798. self.drill_mpass_cb = FCCheckBox()
  799. self.drill_mpass_cb.setObjectName("gdb_e_multidepth")
  800. self.grid5.addWidget(self.multidepth_drill_label, 7, 0)
  801. self.grid5.addWidget(self.drill_mpass_cb, 7, 1)
  802. # Depth Per Pass
  803. self.dpp_drill_label = FCLabel('%s:' % _("DPP"))
  804. self.dpp_drill_label.setToolTip(
  805. _("DPP. Depth per Pass.\n"
  806. "The value used to cut into material on each pass."))
  807. self.drill_maxdepth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  808. self.drill_maxdepth_entry.set_precision(self.decimals)
  809. self.drill_maxdepth_entry.set_range(0, 9999.9999)
  810. self.drill_maxdepth_entry.setSingleStep(0.1)
  811. self.drill_maxdepth_entry.setToolTip(_("Depth of each pass (positive)."))
  812. self.drill_maxdepth_entry.setObjectName("gdb_e_depthperpass")
  813. self.grid5.addWidget(self.dpp_drill_label, 8, 0)
  814. self.grid5.addWidget(self.drill_maxdepth_entry, 8, 1)
  815. # Travel Z (z_move)
  816. self.travelzlabel = FCLabel('%s:' % _('Travel Z'))
  817. self.travelzlabel.setToolTip(
  818. _("Tool height when travelling\n"
  819. "across the XY plane.")
  820. )
  821. self.drill_travelz_entry = FCDoubleSpinner(callback=self.confirmation_message)
  822. self.drill_travelz_entry.set_precision(self.decimals)
  823. if self.machinist_setting == 0:
  824. self.drill_travelz_entry.set_range(0.00001, 9999.9999)
  825. else:
  826. self.drill_travelz_entry.set_range(-9999.9999, 9999.9999)
  827. self.drill_travelz_entry.setSingleStep(0.1)
  828. self.drill_travelz_entry.setObjectName("gdb_e_travelz")
  829. self.grid5.addWidget(self.travelzlabel, 10, 0)
  830. self.grid5.addWidget(self.drill_travelz_entry, 10, 1)
  831. separator_line = QtWidgets.QFrame()
  832. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  833. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  834. self.grid5.addWidget(separator_line, 12, 0, 1, 2)
  835. # Excellon Feedrate Z
  836. self.frzlabel = FCLabel('%s:' % _('Feedrate Z'))
  837. self.frzlabel.setToolTip(
  838. _("Tool speed while drilling\n"
  839. "(in units per minute).\n"
  840. "So called 'Plunge' feedrate.\n"
  841. "This is for linear move G01.")
  842. )
  843. self.drill_feedrate_z_entry = FCDoubleSpinner(callback=self.confirmation_message)
  844. self.drill_feedrate_z_entry.set_precision(self.decimals)
  845. self.drill_feedrate_z_entry.set_range(0.0, 99999.9999)
  846. self.drill_feedrate_z_entry.setSingleStep(0.1)
  847. self.drill_feedrate_z_entry.setObjectName("gdb_e_feedratez")
  848. self.grid5.addWidget(self.frzlabel, 14, 0)
  849. self.grid5.addWidget(self.drill_feedrate_z_entry, 14, 1)
  850. # Excellon Rapid Feedrate
  851. self.feedrate_rapid_label = FCLabel('%s:' % _('Feedrate Rapids'))
  852. self.feedrate_rapid_label.setToolTip(
  853. _("Tool speed while drilling\n"
  854. "(in units per minute).\n"
  855. "This is for the rapid move G00.\n"
  856. "It is useful only for Marlin,\n"
  857. "ignore for any other cases.")
  858. )
  859. self.drill_feedrate_rapid_entry = FCDoubleSpinner(callback=self.confirmation_message)
  860. self.drill_feedrate_rapid_entry.set_precision(self.decimals)
  861. self.drill_feedrate_rapid_entry.set_range(0.0, 99999.9999)
  862. self.drill_feedrate_rapid_entry.setSingleStep(0.1)
  863. self.drill_feedrate_rapid_entry.setObjectName("gdb_e_fr_rapid")
  864. self.grid5.addWidget(self.feedrate_rapid_label, 16, 0)
  865. self.grid5.addWidget(self.drill_feedrate_rapid_entry, 16, 1)
  866. separator_line = QtWidgets.QFrame()
  867. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  868. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  869. self.grid5.addWidget(separator_line, 18, 0, 1, 2)
  870. # Spindlespeed
  871. self.spindle_label = FCLabel('%s:' % _('Spindle speed'))
  872. self.spindle_label.setToolTip(
  873. _("Speed of the spindle\n"
  874. "in RPM (optional)")
  875. )
  876. self.drill_spindlespeed_entry = FCSpinner(callback=self.confirmation_message_int)
  877. self.drill_spindlespeed_entry.set_range(0, 1000000)
  878. self.drill_spindlespeed_entry.set_step(100)
  879. self.drill_spindlespeed_entry.setObjectName("gdb_e_spindlespeed")
  880. self.grid5.addWidget(self.spindle_label, 20, 0)
  881. self.grid5.addWidget(self.drill_spindlespeed_entry, 20, 1)
  882. # Dwell
  883. self.dwell_drill_label = FCLabel('%s:' % _("Dwell"))
  884. self.dwell_drill_label.setToolTip(
  885. _("Dwell.\n"
  886. "Check this if a delay is needed to allow\n"
  887. "the spindle motor to reach its set speed."))
  888. self.drill_dwell_cb = FCCheckBox()
  889. self.drill_dwell_cb.setObjectName("gdb_e_dwell")
  890. self.grid5.addWidget(self.dwell_drill_label, 21, 0)
  891. self.grid5.addWidget(self.drill_dwell_cb, 21, 1)
  892. # Dwelltime
  893. self.dwelltime_drill_lbl = FCLabel('%s:' % _('Dwelltime'))
  894. self.dwelltime_drill_lbl.setToolTip(
  895. _("Dwell Time.\n"
  896. "A delay used to allow the motor spindle reach its set speed."))
  897. self.drill_dwelltime_entry = FCDoubleSpinner(callback=self.confirmation_message)
  898. self.drill_dwelltime_entry.set_precision(self.decimals)
  899. self.drill_dwelltime_entry.set_range(0.0, 9999.9999)
  900. self.drill_dwelltime_entry.setSingleStep(0.1)
  901. self.drill_dwelltime_entry.setObjectName("gdb_e_dwelltime")
  902. self.grid5.addWidget(self.dwelltime_drill_lbl, 22, 0)
  903. self.grid5.addWidget(self.drill_dwelltime_entry, 22, 1)
  904. separator_line = QtWidgets.QFrame()
  905. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  906. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  907. self.grid5.addWidget(separator_line, 24, 0, 1, 2)
  908. # Drill slots
  909. self.drill_slots_drill_lbl = FCLabel('%s:' % _('Drill slots'))
  910. self.drill_slots_drill_lbl.setToolTip(
  911. _("If the selected tool has slots then they will be drilled.")
  912. )
  913. self.drill_slots_cb = FCCheckBox()
  914. self.drill_slots_cb.setObjectName("gdb_e_drill_slots")
  915. self.grid5.addWidget(self.drill_slots_drill_lbl, 26, 0,)
  916. self.grid5.addWidget(self.drill_slots_cb, 26, 1)
  917. # Drill Overlap
  918. self.drill_overlap_label = FCLabel('%s:' % _('Overlap'))
  919. self.drill_overlap_label.setToolTip(
  920. _("How much (percentage) of the tool diameter to overlap previous drill hole.")
  921. )
  922. self.drill_overlap_entry = FCDoubleSpinner(suffix='%', callback=self.confirmation_message)
  923. self.drill_overlap_entry.set_precision(self.decimals)
  924. self.drill_overlap_entry.set_range(0.0, 100.0000)
  925. self.drill_overlap_entry.setSingleStep(0.1)
  926. self.drill_overlap_entry.setObjectName("gdb_e_drill_slots_over")
  927. self.grid5.addWidget(self.drill_overlap_label, 28, 0)
  928. self.grid5.addWidget(self.drill_overlap_entry, 28, 1)
  929. # Last drill in slot
  930. self.last_drill_drill_lbl = FCLabel('%s:' % _('Last drill'))
  931. self.last_drill_drill_lbl.setToolTip(
  932. _("If the slot length is not completely covered by drill holes,\n"
  933. "add a drill hole on the slot end point.")
  934. )
  935. self.drill_last_drill_cb = FCCheckBox()
  936. self.drill_last_drill_cb.setObjectName("gdb_e_drill_last_drill")
  937. self.grid5.addWidget(self.last_drill_drill_lbl, 30, 0, 1, 2)
  938. self.grid5.addWidget(self.drill_last_drill_cb, 30, 1)
  939. # ###########################################################################
  940. # ################### Cutout UI form ########################################
  941. # ###########################################################################
  942. self.grid6 = QtWidgets.QGridLayout()
  943. self.cutout_vlay.addLayout(self.grid6)
  944. self.grid6.setColumnStretch(0, 0)
  945. self.grid6.setColumnStretch(1, 1)
  946. self.cutout_vlay.addStretch()
  947. # Margin
  948. self.cutout_margin_entry = FCDoubleSpinner(callback=self.confirmation_message)
  949. self.cutout_margin_entry.set_range(-9999.9999, 9999.9999)
  950. self.cutout_margin_entry.setSingleStep(0.1)
  951. self.cutout_margin_entry.set_precision(self.decimals)
  952. self.cutout_margin_entry.setObjectName('gdb_ct_margin')
  953. self.cutout_margin_label = FCLabel('%s:' % _("Margin"))
  954. self.cutout_margin_label.setToolTip(
  955. _("Margin over bounds. A positive value here\n"
  956. "will make the cutout of the PCB further from\n"
  957. "the actual PCB border")
  958. )
  959. self.grid6.addWidget(self.cutout_margin_label, 11, 0)
  960. self.grid6.addWidget(self.cutout_margin_entry, 11, 1)
  961. # Gapsize
  962. self.cutout_gapsize = FCDoubleSpinner(callback=self.confirmation_message)
  963. self.cutout_gapsize.set_precision(self.decimals)
  964. self.cutout_gapsize.setObjectName('gdb_ct_gapsize')
  965. self.cutout_gapsize_label = FCLabel('%s:' % _("Gap size"))
  966. self.cutout_gapsize_label.setToolTip(
  967. _("The size of the bridge gaps in the cutout\n"
  968. "used to keep the board connected to\n"
  969. "the surrounding material (the one \n"
  970. "from which the PCB is cutout).")
  971. )
  972. self.grid6.addWidget(self.cutout_gapsize_label, 13, 0)
  973. self.grid6.addWidget(self.cutout_gapsize, 13, 1)
  974. # Gap Type
  975. self.gaptype_label = FCLabel('%s:' % _("Gap type"))
  976. self.gaptype_label.setToolTip(
  977. _("The type of gap:\n"
  978. "- Bridge -> the cutout will be interrupted by bridges\n"
  979. "- Thin -> same as 'bridge' but it will be thinner by partially milling the gap\n"
  980. "- M-Bites -> 'Mouse Bites' - same as 'bridge' but covered with drill holes")
  981. )
  982. self.cutout_gaptype_radio = RadioSet(
  983. [
  984. {'label': _('Bridge'), 'value': 'b'},
  985. {'label': _('Thin'), 'value': 'bt'},
  986. {'label': "M-Bites", 'value': 'mb'}
  987. ],
  988. stretch=True
  989. )
  990. self.cutout_gaptype_radio.setObjectName('gdb_ct_gap_type')
  991. self.grid6.addWidget(self.gaptype_label, 15, 0)
  992. self.grid6.addWidget(self.cutout_gaptype_radio, 15, 1)
  993. # Thin gaps Depth
  994. self.thin_depth_label = FCLabel('%s:' % _("Depth"))
  995. self.thin_depth_label.setToolTip(
  996. _("The depth until the milling is done\n"
  997. "in order to thin the gaps.")
  998. )
  999. self.cutout_thin_depth_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1000. self.cutout_thin_depth_entry.set_precision(self.decimals)
  1001. self.cutout_thin_depth_entry.setObjectName('gdb_ct_gap_depth')
  1002. if self.machinist_setting == 0:
  1003. self.cutout_thin_depth_entry.setRange(-9999.9999, -0.00001)
  1004. else:
  1005. self.cutout_thin_depth_entry.setRange(-9999.9999, 9999.9999)
  1006. self.cutout_thin_depth_entry.setSingleStep(0.1)
  1007. self.grid6.addWidget(self.thin_depth_label, 17, 0)
  1008. self.grid6.addWidget(self.cutout_thin_depth_entry, 17, 1)
  1009. # Mouse Bites Tool Diameter
  1010. self.mb_dia_label = FCLabel('%s:' % _("Tool Diameter"))
  1011. self.mb_dia_label.setToolTip(
  1012. _("The drill hole diameter when doing mouse bites.")
  1013. )
  1014. self.cutout_mb_dia_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1015. self.cutout_mb_dia_entry.set_precision(self.decimals)
  1016. self.cutout_mb_dia_entry.setRange(0, 100.0000)
  1017. self.cutout_mb_dia_entry.setObjectName('gdb_ct_mb_dia')
  1018. self.grid6.addWidget(self.mb_dia_label, 19, 0)
  1019. self.grid6.addWidget(self.cutout_mb_dia_entry, 19, 1)
  1020. # Mouse Bites Holes Spacing
  1021. self.mb_spacing_label = FCLabel('%s:' % _("Spacing"))
  1022. self.mb_spacing_label.setToolTip(
  1023. _("The spacing between drill holes when doing mouse bites.")
  1024. )
  1025. self.cutout_mb_spacing_entry = FCDoubleSpinner(callback=self.confirmation_message)
  1026. self.cutout_mb_spacing_entry.set_precision(self.decimals)
  1027. self.cutout_mb_spacing_entry.setRange(0, 100.0000)
  1028. self.cutout_mb_spacing_entry.setObjectName('gdb_ct_mb_spacing')
  1029. self.grid6.addWidget(self.mb_spacing_label, 21, 0)
  1030. self.grid6.addWidget(self.cutout_mb_spacing_entry, 21, 1)
  1031. # How gaps wil be rendered:
  1032. # lr - left + right
  1033. # tb - top + bottom
  1034. # 4 - left + right +top + bottom
  1035. # 2lr - 2*left + 2*right
  1036. # 2tb - 2*top + 2*bottom
  1037. # 8 - 2*left + 2*right +2*top + 2*bottom
  1038. # Surrounding convex box shape
  1039. self.cutout_convex_box = FCCheckBox('%s' % _("Convex Shape"))
  1040. # self.convex_box_label = FCLabel('%s' % _("Convex Sh."))
  1041. self.cutout_convex_box.setToolTip(
  1042. _("Create a convex shape surrounding the entire PCB.\n"
  1043. "Used only if the source object type is Gerber.")
  1044. )
  1045. self.cutout_convex_box.setObjectName('gdb_ct_convex')
  1046. self.grid6.addWidget(self.cutout_convex_box, 23, 0, 1, 2)
  1047. # Gaps
  1048. self.cutout_gaps_label = FCLabel('%s:' % _('Gaps'))
  1049. self.cutout_gaps_label.setToolTip(
  1050. _("Number of gaps used for the Automatic cutout.\n"
  1051. "There can be maximum 8 bridges/gaps.\n"
  1052. "The choices are:\n"
  1053. "- None - no gaps\n"
  1054. "- lr - left + right\n"
  1055. "- tb - top + bottom\n"
  1056. "- 4 - left + right +top + bottom\n"
  1057. "- 2lr - 2*left + 2*right\n"
  1058. "- 2tb - 2*top + 2*bottom\n"
  1059. "- 8 - 2*left + 2*right +2*top + 2*bottom")
  1060. )
  1061. self.cutout_gaps = FCComboBox()
  1062. gaps_items = ['None', 'LR', 'TB', '4', '2LR', '2TB', '8']
  1063. self.cutout_gaps.addItems(gaps_items)
  1064. self.cutout_gaps.setObjectName('gdb_ct_gaps')
  1065. self.grid6.addWidget(self.cutout_gaps_label, 25, 0)
  1066. self.grid6.addWidget(self.cutout_gaps, 25, 1)
  1067. # ####################################################################
  1068. # ####################################################################
  1069. # GUI for the lower part of the window
  1070. # ####################################################################
  1071. # ####################################################################
  1072. new_vlay = QtWidgets.QVBoxLayout()
  1073. self.g_lay.addLayout(new_vlay, 1, 0, 1, 2)
  1074. self.buttons_frame = QtWidgets.QFrame()
  1075. self.buttons_frame.setContentsMargins(0, 0, 0, 0)
  1076. new_vlay.addWidget(self.buttons_frame)
  1077. self.buttons_box = QtWidgets.QHBoxLayout()
  1078. self.buttons_box.setContentsMargins(0, 0, 0, 0)
  1079. self.buttons_frame.setLayout(self.buttons_box)
  1080. self.buttons_frame.show()
  1081. self.add_entry_btn = FCButton(_("Add Tool in DB"))
  1082. self.add_entry_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/plus16.png'))
  1083. self.add_entry_btn.setToolTip(
  1084. _("Add a new tool in the Tools Database.\n"
  1085. "It will be used in the Geometry UI.\n"
  1086. "You can edit it after it is added.")
  1087. )
  1088. self.buttons_box.addWidget(self.add_entry_btn)
  1089. # add_fct_entry_btn = FCButton(_("Add Paint/NCC Tool in DB"))
  1090. # add_fct_entry_btn.setToolTip(
  1091. # _("Add a new tool in the Tools Database.\n"
  1092. # "It will be used in the Paint/NCC Tools UI.\n"
  1093. # "You can edit it after it is added.")
  1094. # )
  1095. # self.buttons_box.addWidget(add_fct_entry_btn)
  1096. self.remove_entry_btn = FCButton(_("Delete Tool from DB"))
  1097. self.remove_entry_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/trash16.png'))
  1098. self.remove_entry_btn.setToolTip(
  1099. _("Remove a selection of tools in the Tools Database.")
  1100. )
  1101. self.buttons_box.addWidget(self.remove_entry_btn)
  1102. self.export_db_btn = FCButton(_("Export DB"))
  1103. self.export_db_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/export.png'))
  1104. self.export_db_btn.setToolTip(
  1105. _("Save the Tools Database to a custom text file.")
  1106. )
  1107. self.buttons_box.addWidget(self.export_db_btn)
  1108. self.import_db_btn = FCButton(_("Import DB"))
  1109. self.import_db_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/import.png'))
  1110. self.import_db_btn.setToolTip(
  1111. _("Load the Tools Database information's from a custom text file.")
  1112. )
  1113. self.buttons_box.addWidget(self.import_db_btn)
  1114. self.save_db_btn = FCButton(_("Save DB"))
  1115. self.save_db_btn.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
  1116. self.save_db_btn.setToolTip(
  1117. _("Save the Tools Database information's.")
  1118. )
  1119. self.buttons_box.addWidget(self.save_db_btn)
  1120. self.add_tool_from_db = FCButton(_("Transfer the Tool"))
  1121. self.add_tool_from_db.setToolTip(
  1122. _("Insert a new tool in the Tools Table of the\n"
  1123. "object/application tool after selecting a tool\n"
  1124. "in the Tools Database.")
  1125. )
  1126. self.add_tool_from_db.setStyleSheet("""
  1127. QPushButton
  1128. {
  1129. font-weight: bold;
  1130. color: green;
  1131. }
  1132. """)
  1133. self.add_tool_from_db.hide()
  1134. self.cancel_tool_from_db = FCButton(_("Cancel"))
  1135. self.cancel_tool_from_db.hide()
  1136. hlay = QtWidgets.QHBoxLayout()
  1137. tree_layout.addLayout(hlay)
  1138. hlay.addWidget(self.add_tool_from_db)
  1139. hlay.addWidget(self.cancel_tool_from_db)
  1140. # hlay.addStretch()
  1141. # ############################ FINSIHED GUI ###################################
  1142. # #############################################################################
  1143. def confirmation_message(self, accepted, minval, maxval):
  1144. if accepted is False:
  1145. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
  1146. self.decimals,
  1147. minval,
  1148. self.decimals,
  1149. maxval), False)
  1150. else:
  1151. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  1152. def confirmation_message_int(self, accepted, minval, maxval):
  1153. if accepted is False:
  1154. self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
  1155. (_("Edited value is out of range"), minval, maxval), False)
  1156. else:
  1157. self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
  1158. class ToolsDB2(QtWidgets.QWidget):
  1159. mark_tools_rows = QtCore.pyqtSignal()
  1160. def __init__(self, app, callback_on_tool_request, parent=None):
  1161. super(ToolsDB2, self).__init__(parent)
  1162. self.app = app
  1163. self.app_ui = self.app.ui
  1164. self.decimals = self.app.decimals
  1165. self.on_tool_request = callback_on_tool_request
  1166. self.tools_db_changed_flag = False
  1167. '''
  1168. dict to hold all the tools in the Tools DB
  1169. format:
  1170. {
  1171. tool_id: {
  1172. 'name': 'new_tool'
  1173. 'tooldia': self.app.defaults["geometry_cnctooldia"]
  1174. 'offset': 'Path'
  1175. 'offset_value': 0.0
  1176. 'type': _('Rough'),
  1177. 'tool_type': 'C1'
  1178. 'data': dict()
  1179. }
  1180. }
  1181. '''
  1182. self.db_tool_dict = {}
  1183. # ##############################################################################
  1184. # ##############################################################################
  1185. # TOOLS DATABASE UI
  1186. # ##############################################################################
  1187. # ##############################################################################
  1188. layout = QtWidgets.QGridLayout()
  1189. layout.setColumnStretch(0, 0)
  1190. layout.setColumnStretch(1, 1)
  1191. self.setLayout(layout)
  1192. self.ui = ToolsDB2UI(app=self.app, grid_layout=layout)
  1193. # ##############################################################################
  1194. # ##############################################################################
  1195. # ########## SETUP THE DICTIONARIES THAT HOLD THE WIDGETS #####################
  1196. # ##############################################################################
  1197. # ##############################################################################
  1198. self.form_fields = {
  1199. "tool_target": self.ui.tool_op_combo,
  1200. "tol_min": self.ui.tol_min_entry,
  1201. "tol_max": self.ui.tol_max_entry,
  1202. "name": self.ui.name_entry,
  1203. "tooldia": self.ui.dia_entry,
  1204. # Milling
  1205. "tool_type": self.ui.mill_shape_combo,
  1206. "cutz": self.ui.mill_cutz_entry,
  1207. "multidepth": self.ui.mill_multidepth_cb,
  1208. "depthperpass": self.ui.mill_multidepth_entry,
  1209. "travelz": self.ui.mill_travelz_entry,
  1210. "feedrate": self.ui.mill_frxy_entry,
  1211. "feedrate_z": self.ui.mill_frz_entry,
  1212. "spindlespeed": self.ui.mill_spindle_entry,
  1213. "dwell": self.ui.mill_dwell_cb,
  1214. "dwelltime": self.ui.mill_dwelltime_entry,
  1215. "type": self.ui.mill_type_combo,
  1216. "offset": self.ui.mill_tooloffset_combo,
  1217. "offset_value": self.ui.mill_custom_offset_entry,
  1218. "vtipdia": self.ui.mill_vdia_entry,
  1219. "vtipangle": self.ui.mill_vangle_entry,
  1220. "feedrate_rapid": self.ui.mill_frapids_entry,
  1221. "extracut": self.ui.mill_ecut_cb,
  1222. "extracut_length": self.ui.mill_ecut_length_entry,
  1223. # NCC
  1224. "tools_ncc_operation": self.ui.ncc_op_radio,
  1225. "tools_ncc_milling_type": self.ui.ncc_milling_type_radio,
  1226. "tools_ncc_overlap": self.ui.ncc_overlap_entry,
  1227. "tools_ncc_margin": self.ui.ncc_margin_entry,
  1228. "tools_ncc_method": self.ui.ncc_method_combo,
  1229. "tools_ncc_connect": self.ui.ncc_connect_cb,
  1230. "tools_ncc_contour": self.ui.ncc_contour_cb,
  1231. "tools_ncc_offset_choice": self.ui.ncc_choice_offset_cb,
  1232. "tools_ncc_offset_value": self.ui.ncc_offset_spinner,
  1233. # Paint
  1234. "tools_paint_overlap": self.ui.paint_overlap_entry,
  1235. "tools_paint_offset": self.ui.paint_offset_entry,
  1236. "tools_paint_method": self.ui.paint_method_combo,
  1237. "tools_paint_connect": self.ui.path_connect_cb,
  1238. "tools_paint_contour": self.ui.paint_contour_cb,
  1239. # Isolation
  1240. "tools_iso_passes": self.ui.iso_passes_entry,
  1241. "tools_iso_overlap": self.ui.iso_overlap_entry,
  1242. "tools_iso_milling_type": self.ui.iso_milling_type_radio,
  1243. "tools_iso_follow": self.ui.iso_follow_cb,
  1244. "tools_iso_isotype": self.ui.iso_type_radio,
  1245. # Drilling
  1246. "tools_drill_cutz": self.ui.drill_cutz_entry,
  1247. "tools_drill_multidepth": self.ui.drill_mpass_cb,
  1248. "tools_drill_depthperpass": self.ui.drill_maxdepth_entry,
  1249. "tools_drill_travelz": self.ui.drill_travelz_entry,
  1250. "tools_drill_feedrate_z": self.ui.drill_feedrate_z_entry,
  1251. "tools_drill_feedrate_rapid": self.ui.drill_feedrate_rapid_entry,
  1252. "tools_drill_spindlespeed": self.ui.drill_spindlespeed_entry,
  1253. "tools_drill_dwell": self.ui.drill_dwell_cb,
  1254. "tools_drill_dwelltime": self.ui.drill_dwelltime_entry,
  1255. "tools_drill_offset": self.ui.drill_offset_entry,
  1256. "tools_drill_drill_slots": self.ui.drill_slots_cb,
  1257. "tools_drill_drill_overlap": self.ui.drill_overlap_entry,
  1258. "tools_drill_last_drill": self.ui.drill_last_drill_cb,
  1259. # Cutout
  1260. "tools_cutout_margin": self.ui.cutout_margin_entry,
  1261. "tools_cutout_gapsize": self.ui.cutout_gapsize,
  1262. "tools_cutout_gaps_ff": self.ui.cutout_gaps,
  1263. "tools_cutout_convexshape": self.ui.cutout_convex_box,
  1264. "tools_cutout_gap_type": self.ui.cutout_gaptype_radio,
  1265. "tools_cutout_gap_depth": self.ui.cutout_thin_depth_entry,
  1266. "tools_cutout_mb_dia": self.ui.cutout_mb_dia_entry,
  1267. "tools_cutout_mb_spacing": self.ui.cutout_mb_spacing_entry,
  1268. }
  1269. self.name2option = {
  1270. "gdb_tool_target": "tool_target",
  1271. "gdb_tol_min": "tol_min",
  1272. "gdb_tol_max": "tol_max",
  1273. "gdb_name": "name",
  1274. "gdb_dia": "tooldia",
  1275. # Milling
  1276. "gdb_shape": "tool_type",
  1277. "gdb_cutz": "cutz",
  1278. "gdb_multidepth": "multidepth",
  1279. "gdb_multidepth_entry": "depthperpass",
  1280. "gdb_travelz": "travelz",
  1281. "gdb_frxy": "feedrate",
  1282. "gdb_frz": "feedrate_z",
  1283. "gdb_spindle": "spindlespeed",
  1284. "gdb_dwell": "dwell",
  1285. "gdb_dwelltime": "dwelltime",
  1286. "gdb_type": "type",
  1287. "gdb_tool_offset": "offset",
  1288. "gdb_custom_offset": "offset_value",
  1289. "gdb_vdia": "vtipdia",
  1290. "gdb_vangle": "vtipangle",
  1291. "gdb_frapids": "feedrate_rapid",
  1292. "gdb_ecut": "extracut",
  1293. "gdb_ecut_length": "extracut_length",
  1294. # NCC
  1295. "gdb_n_operation": "tools_ncc_operation",
  1296. "gdb_n_overlap": "tools_ncc_overlap",
  1297. "gdb_n_margin": "tools_ncc_margin",
  1298. "gdb_n_method": "tools_ncc_method",
  1299. "gdb_n_connect": "tools_ncc_connect",
  1300. "gdb_n_contour": "tools_ncc_contour",
  1301. "gdb_n_offset": "tools_ncc_offset_choice",
  1302. "gdb_n_offset_value": "tools_ncc_offset_value",
  1303. "gdb_n_milling_type": "tools_ncc_milling_type",
  1304. # Paint
  1305. 'gdb_p_overlap': "tools_paint_overlap",
  1306. 'gdb_p_offset': "tools_paint_offset",
  1307. 'gdb_p_method': "tools_paint_method",
  1308. 'gdb_p_connect': "tools_paint_connect",
  1309. 'gdb_p_contour': "tools_paint_contour",
  1310. # Isolation
  1311. "gdb_i_passes": "tools_iso_passes",
  1312. "gdb_i_overlap": "tools_iso_overlap",
  1313. "gdb_i_milling_type": "tools_iso_milling_type",
  1314. "gdb_i_follow": "tools_iso_follow",
  1315. "gdb_i_iso_type": "tools_iso_isotype",
  1316. # Drilling
  1317. "gdb_e_cutz": "tools_drill_cutz",
  1318. "gdb_e_multidepth": "tools_drill_multidepth",
  1319. "gdb_e_depthperpass": "tools_drill_depthperpass",
  1320. "gdb_e_travelz": "tools_drill_travelz",
  1321. "gdb_e_feedratez": "tools_drill_feedrate_z",
  1322. "gdb_e_fr_rapid": "tools_drill_feedrate_rapid",
  1323. "gdb_e_spindlespeed": "tools_drill_spindlespeed",
  1324. "gdb_e_dwell": "tools_drill_dwell",
  1325. "gdb_e_dwelltime": "tools_drill_dwelltime",
  1326. "gdb_e_offset": "tools_drill_offset",
  1327. "gdb_e_drill_slots": "tools_drill_drill_slots",
  1328. "gdb_e_drill_slots_over": "tools_drill_drill_overlap",
  1329. "gdb_e_drill_last_drill": "tools_drill_last_drill",
  1330. # Cutout
  1331. "gdb_ct_margin": "tools_cutout_margin",
  1332. "gdb_ct_gapsize": "tools_cutout_gapsize",
  1333. "gdb_ct_gaps": "tools_cutout_gaps_ff",
  1334. "gdb_ct_convex": "tools_cutout_convexshape",
  1335. "gdb_ct_gap_type": "tools_cutout_gap_type",
  1336. "gdb_ct_gap_depth": "tools_cutout_gap_depth",
  1337. "gdb_ct_mb_dia": "tools_cutout_mb_dia",
  1338. "gdb_ct_mb_spacing": "tools_cutout_mb_spacing"
  1339. }
  1340. self.current_toolid = None
  1341. # variable to show if double clicking and item will trigger adding a tool from DB
  1342. self.ok_to_add = False
  1343. # ##############################################################################
  1344. # ######################## SIGNALS #############################################
  1345. # ##############################################################################
  1346. self.ui.add_entry_btn.clicked.connect(self.on_tool_add)
  1347. self.ui.remove_entry_btn.clicked.connect(self.on_tool_delete)
  1348. self.ui.export_db_btn.clicked.connect(self.on_export_tools_db_file)
  1349. self.ui.import_db_btn.clicked.connect(self.on_import_tools_db_file)
  1350. self.ui.save_db_btn.clicked.connect(self.on_save_db_btn_click)
  1351. # closebtn.clicked.connect(self.accept)
  1352. self.ui.add_tool_from_db.clicked.connect(self.on_tool_requested_from_app)
  1353. self.ui.cancel_tool_from_db.clicked.connect(self.on_cancel_tool)
  1354. # self.ui.tree_widget.selectionModel().selectionChanged.connect(self.on_list_selection_change)
  1355. self.ui.tree_widget.currentItemChanged.connect(self.on_list_selection_change)
  1356. self.ui.tree_widget.itemChanged.connect(self.on_list_item_edited)
  1357. self.ui.tree_widget.customContextMenuRequested.connect(self.on_menu_request)
  1358. self.ui.tree_widget.itemDoubleClicked.connect(self.on_item_double_clicked)
  1359. self.ui.tool_op_combo.currentIndexChanged.connect(self.on_tool_target_changed)
  1360. self.setup_db_ui()
  1361. def on_menu_request(self, pos):
  1362. menu = QtWidgets.QMenu()
  1363. add_tool = menu.addAction(QtGui.QIcon(self.app.resource_location + '/plus16.png'), _("Add to DB"))
  1364. add_tool.triggered.connect(self.on_tool_add)
  1365. copy_tool = menu.addAction(QtGui.QIcon(self.app.resource_location + '/copy16.png'), _("Copy from DB"))
  1366. copy_tool.triggered.connect(self.on_tool_copy)
  1367. delete_tool = menu.addAction(QtGui.QIcon(self.app.resource_location + '/delete32.png'), _("Delete from DB"))
  1368. delete_tool.triggered.connect(self.on_tool_delete)
  1369. # sep = menu.addSeparator()
  1370. save_changes = menu.addAction(QtGui.QIcon(self.app.resource_location + '/save_as.png'), _("Save changes"))
  1371. save_changes.triggered.connect(self.on_save_changes)
  1372. # tree_item = self.ui.tree_widget.itemAt(pos)
  1373. menu.exec(self.ui.tree_widget.viewport().mapToGlobal(pos))
  1374. def on_save_changes(self):
  1375. widget_name = self.app_ui.plot_tab_area.currentWidget().objectName()
  1376. if widget_name == 'database_tab':
  1377. # Tools DB saved, update flag
  1378. self.app.tools_db_changed_flag = False
  1379. self.app.tools_db_tab.on_save_tools_db()
  1380. def on_item_double_clicked(self, item, column):
  1381. if column == 0 and self.ok_to_add is True:
  1382. self.ok_to_add = False
  1383. self.on_tool_requested_from_app()
  1384. def on_list_selection_change(self, current, previous):
  1385. self.ui_disconnect()
  1386. self.current_toolid = int(current.text(0))
  1387. self.storage_to_form(self.db_tool_dict[current.text(0)])
  1388. self.ui_connect()
  1389. def on_list_item_edited(self, item, column):
  1390. if column == 0:
  1391. return
  1392. self.ui.name_entry.set_value(item.text(1))
  1393. def storage_to_form(self, dict_storage):
  1394. self.ui_disconnect()
  1395. for form_key in self.form_fields:
  1396. for storage_key in dict_storage:
  1397. if form_key == storage_key:
  1398. try:
  1399. self.form_fields[form_key].set_value(dict_storage[form_key])
  1400. except Exception as e:
  1401. print(str(e))
  1402. if storage_key == 'data':
  1403. for data_key in dict_storage[storage_key]:
  1404. if form_key == data_key:
  1405. try:
  1406. self.form_fields[form_key].set_value(dict_storage['data'][data_key])
  1407. except Exception as e:
  1408. print(str(e))
  1409. self.ui_connect()
  1410. def form_to_storage(self, tool):
  1411. self.ui_disconnect()
  1412. widget_changed = self.sender()
  1413. wdg_objname = widget_changed.objectName()
  1414. option_changed = self.name2option[wdg_objname]
  1415. tooluid_item = int(tool)
  1416. for tooluid_key, tooluid_val in self.db_tool_dict.items():
  1417. if int(tooluid_key) == tooluid_item:
  1418. new_option_value = self.form_fields[option_changed].get_value()
  1419. if option_changed in tooluid_val:
  1420. tooluid_val[option_changed] = new_option_value
  1421. if option_changed in tooluid_val['data']:
  1422. tooluid_val['data'][option_changed] = new_option_value
  1423. self.ui_connect()
  1424. def setup_db_ui(self):
  1425. filename = self.app.tools_database_path()
  1426. # load the database tools from the file
  1427. try:
  1428. with open(filename) as f:
  1429. tools = f.read()
  1430. except IOError:
  1431. self.app.log.error("Could not load tools DB file.")
  1432. self.app.inform.emit('[ERROR] %s' % _("Could not load Tools DB file."))
  1433. return
  1434. try:
  1435. self.db_tool_dict = json.loads(tools)
  1436. except Exception:
  1437. e = sys.exc_info()[0]
  1438. self.app.log.error(str(e))
  1439. self.app.inform.emit('[ERROR] %s' % _("Failed to parse Tools DB file."))
  1440. return
  1441. self.app.inform.emit('[success] %s: %s' % (_("Loaded Tools DB from"), filename))
  1442. self.build_db_ui()
  1443. def build_db_ui(self):
  1444. self.ui_disconnect()
  1445. nr_crt = 0
  1446. parent = self.ui.tree_widget
  1447. self.ui.tree_widget.blockSignals(True)
  1448. self.ui.tree_widget.clear()
  1449. self.ui.tree_widget.blockSignals(False)
  1450. for toolid, dict_val in self.db_tool_dict.items():
  1451. row = nr_crt
  1452. nr_crt += 1
  1453. t_name = dict_val['name']
  1454. try:
  1455. # self.add_tool_table_line(row, name=t_name, tooldict=dict_val)
  1456. self.ui.tree_widget.blockSignals(True)
  1457. try:
  1458. self.ui.tree_widget.addParentEditable(parent=parent, title=[str(row+1), t_name], editable=True)
  1459. except Exception as e:
  1460. print('FlatCAMCoomn.ToolDB2.build_db_ui() -> ', str(e))
  1461. self.ui.tree_widget.blockSignals(False)
  1462. except Exception as e:
  1463. self.app.log.debug("ToolDB.build_db_ui.add_tool_table_line() --> %s" % str(e))
  1464. if self.current_toolid is None or self.current_toolid < 1:
  1465. if self.db_tool_dict:
  1466. self.storage_to_form(self.db_tool_dict['1'])
  1467. # Enable appGUI
  1468. try:
  1469. self.on_tool_target_changed(val=self.db_tool_dict['1']['data']['tool_target'])
  1470. except KeyError:
  1471. self.on_tool_target_changed(val=_("General"))
  1472. self.ui.tree_widget.setCurrentItem(self.ui.tree_widget.topLevelItem(0))
  1473. # self.ui.tree_widget.setFocus()
  1474. else:
  1475. # Disable appGUI
  1476. self.ui.tool_description_box.show()
  1477. self.ui.milling_box.show()
  1478. self.ui.ncc_box.show()
  1479. self.ui.paint_box.show()
  1480. self.ui.iso_box.show()
  1481. self.ui.drill_box.show()
  1482. self.ui.cutout_box.show()
  1483. self.ui.tool_description_box.setEnabled(False)
  1484. self.ui.milling_box.setEnabled(False)
  1485. self.ui.ncc_box.setEnabled(False)
  1486. self.ui.paint_box.setEnabled(False)
  1487. self.ui.iso_box.setEnabled(False)
  1488. self.ui.drill_box.setEnabled(False)
  1489. self.ui.cutout_box.setEnabled(False)
  1490. else:
  1491. self.storage_to_form(self.db_tool_dict[str(self.current_toolid)])
  1492. self.ui_connect()
  1493. def on_tool_target_changed(self, index=None, val=None):
  1494. if val is None:
  1495. tool_target = self.ui.tool_op_combo.get_value()
  1496. else:
  1497. tool_target = val
  1498. self.ui.tool_description_box.setEnabled(True)
  1499. if self.db_tool_dict:
  1500. if tool_target == 0: # _("General")
  1501. self.ui.milling_box.setEnabled(True)
  1502. self.ui.ncc_box.setEnabled(True)
  1503. self.ui.paint_box.setEnabled(True)
  1504. self.ui.iso_box.setEnabled(True)
  1505. self.ui.drill_box.setEnabled(True)
  1506. self.ui.cutout_box.setEnabled(True)
  1507. self.ui.milling_box.show()
  1508. self.ui.ncc_box.show()
  1509. self.ui.paint_box.show()
  1510. self.ui.iso_box.show()
  1511. self.ui.drill_box.show()
  1512. self.ui.cutout_box.show()
  1513. else:
  1514. self.ui.milling_box.hide()
  1515. self.ui.ncc_box.hide()
  1516. self.ui.paint_box.hide()
  1517. self.ui.iso_box.hide()
  1518. self.ui.drill_box.hide()
  1519. self.ui.cutout_box.hide()
  1520. if tool_target == 1: # _("Milling")
  1521. self.ui.milling_box.setEnabled(True)
  1522. self.ui.milling_box.show()
  1523. if tool_target == 2: # _("Drilling")
  1524. self.ui.drill_box.setEnabled(True)
  1525. self.ui.drill_box.show()
  1526. if tool_target == 3: # _("Isolation")
  1527. self.ui.iso_box.setEnabled(True)
  1528. self.ui.iso_box.show()
  1529. self.ui.milling_box.setEnabled(True)
  1530. self.ui.milling_box.show()
  1531. if tool_target == 4: # _("Paint")
  1532. self.ui.paint_box.setEnabled(True)
  1533. self.ui.paint_box.show()
  1534. self.ui.milling_box.setEnabled(True)
  1535. self.ui.milling_box.show()
  1536. if tool_target == 5: # _("NCC")
  1537. self.ui.ncc_box.setEnabled(True)
  1538. self.ui.ncc_box.show()
  1539. self.ui.milling_box.setEnabled(True)
  1540. self.ui.milling_box.show()
  1541. if tool_target == 6: # _("Cutout")
  1542. self.ui.cutout_box.setEnabled(True)
  1543. self.ui.cutout_box.show()
  1544. self.ui.milling_box.setEnabled(True)
  1545. self.ui.milling_box.show()
  1546. def on_tool_add(self):
  1547. """
  1548. Add a tool in the DB Tool Table
  1549. :return: None
  1550. """
  1551. default_data = {}
  1552. default_data.update({
  1553. "plot": True,
  1554. "tool_target": 0, # _("General")
  1555. "tol_min": 0.0,
  1556. "tol_max": 0.0,
  1557. # Milling
  1558. "cutz": float(self.app.defaults["geometry_cutz"]),
  1559. "multidepth": self.app.defaults["geometry_multidepth"],
  1560. "depthperpass": float(self.app.defaults["geometry_depthperpass"]),
  1561. "vtipdia": float(self.app.defaults["geometry_vtipdia"]),
  1562. "vtipangle": float(self.app.defaults["geometry_vtipangle"]),
  1563. "travelz": float(self.app.defaults["geometry_travelz"]),
  1564. "feedrate": float(self.app.defaults["geometry_feedrate"]),
  1565. "feedrate_z": float(self.app.defaults["geometry_feedrate_z"]),
  1566. "feedrate_rapid": float(self.app.defaults["geometry_feedrate_rapid"]),
  1567. "spindlespeed": self.app.defaults["geometry_spindlespeed"],
  1568. "dwell": self.app.defaults["geometry_dwell"],
  1569. "dwelltime": float(self.app.defaults["geometry_dwelltime"]),
  1570. "ppname_g": self.app.defaults["geometry_ppname_g"],
  1571. "extracut": self.app.defaults["geometry_extracut"],
  1572. "extracut_length": float(self.app.defaults["geometry_extracut_length"]),
  1573. "toolchange": self.app.defaults["geometry_toolchange"],
  1574. "toolchangexy": self.app.defaults["geometry_toolchangexy"],
  1575. "toolchangez": float(self.app.defaults["geometry_toolchangez"]),
  1576. "startz": self.app.defaults["geometry_startz"],
  1577. "endz": float(self.app.defaults["geometry_endz"]),
  1578. # NCC
  1579. "tools_ncc_operation": self.app.defaults["tools_ncc_operation"],
  1580. "tools_ncc_milling_type": self.app.defaults["tools_ncc_milling_type"],
  1581. "tools_ncc_overlap": float(self.app.defaults["tools_ncc_overlap"]),
  1582. "tools_ncc_margin": float(self.app.defaults["tools_ncc_margin"]),
  1583. "tools_ncc_method": self.app.defaults["tools_ncc_method"],
  1584. "tools_ncc_connect": self.app.defaults["tools_ncc_connect"],
  1585. "tools_ncc_contour": self.app.defaults["tools_ncc_contour"],
  1586. "tools_ncc_offset_choice": self.app.defaults["tools_ncc_offset_choice"],
  1587. "tools_ncc_offset_value": float(self.app.defaults["tools_ncc_offset_value"]),
  1588. # Paint
  1589. "tools_paint_overlap": float(self.app.defaults["tools_paint_overlap"]),
  1590. "tools_paint_offset": float(self.app.defaults["tools_paint_offset"]),
  1591. "tools_paint_method": self.app.defaults["tools_paint_method"],
  1592. "tools_paint_connect": self.app.defaults["tools_paint_connect"],
  1593. "tools_paint_contour": self.app.defaults["tools_paint_contour"],
  1594. # Isolation
  1595. "tools_iso_passes": int(self.app.defaults["tools_iso_passes"]),
  1596. "tools_iso_overlap": float(self.app.defaults["tools_iso_overlap"]),
  1597. "tools_iso_milling_type": self.app.defaults["tools_iso_milling_type"],
  1598. "tools_iso_follow": self.app.defaults["tools_iso_follow"],
  1599. "tools_iso_isotype": self.app.defaults["tools_iso_isotype"],
  1600. # Drilling
  1601. "tools_drill_cutz": float(self.app.defaults["tools_drill_cutz"]),
  1602. "tools_drill_multidepth": self.app.defaults["tools_drill_multidepth"],
  1603. "tools_drill_depthperpass": float(self.app.defaults["tools_drill_depthperpass"]),
  1604. "tools_drill_travelz": float(self.app.defaults["tools_drill_travelz"]),
  1605. "tools_drill_feedrate_z": float(self.app.defaults["tools_drill_feedrate_z"]),
  1606. "tools_drill_feedrate_rapid": float(self.app.defaults["tools_drill_feedrate_rapid"]),
  1607. "tools_drill_spindlespeed": float(self.app.defaults["tools_drill_spindlespeed"]),
  1608. "tools_drill_dwell": self.app.defaults["tools_drill_dwell"],
  1609. "tools_drill_offset": float(self.app.defaults["tools_drill_offset"]),
  1610. "tools_drill_drill_slots": self.app.defaults["tools_drill_drill_slots"],
  1611. "tools_drill_drill_overlap": float(self.app.defaults["tools_drill_drill_overlap"]),
  1612. "tools_drill_last_drill": self.app.defaults["tools_drill_last_drill"],
  1613. # Cutout
  1614. "tools_cutout_margin": float(self.app.defaults["tools_cutout_margin"]),
  1615. "tools_cutout_gapsize": float(self.app.defaults["tools_cutout_gapsize"]),
  1616. "tools_cutout_gaps_ff": self.app.defaults["tools_cutout_gaps_ff"],
  1617. "tools_cutout_convexshape": self.app.defaults["tools_cutout_convexshape"],
  1618. "tools_cutout_gap_type": self.app.defaults["tools_cutout_gap_type"],
  1619. "tools_cutout_gap_depth": float(self.app.defaults["tools_cutout_gap_depth"]),
  1620. "tools_cutout_mb_dia": float(self.app.defaults["tools_cutout_mb_dia"]),
  1621. "tools_cutout_mb_spacing": float(self.app.defaults["tools_cutout_mb_spacing"])
  1622. })
  1623. temp = []
  1624. for k, v in self.db_tool_dict.items():
  1625. if "new_tool_" in v['name']:
  1626. temp.append(float(v['name'].rpartition('_')[2]))
  1627. if temp:
  1628. new_name = "new_tool_%d" % int(max(temp) + 1)
  1629. else:
  1630. new_name = "new_tool_1"
  1631. dict_elem = {}
  1632. dict_elem['name'] = new_name
  1633. if type(self.app.defaults["geometry_cnctooldia"]) == float:
  1634. dict_elem['tooldia'] = self.app.defaults["geometry_cnctooldia"]
  1635. else:
  1636. try:
  1637. tools_string = self.app.defaults["geometry_cnctooldia"].split(",")
  1638. tools_diameters = [eval(a) for a in tools_string if a != '']
  1639. dict_elem['tooldia'] = tools_diameters[0] if tools_diameters else 0.0
  1640. except Exception as e:
  1641. self.app.log.debug("ToolDB.on_tool_add() --> %s" % str(e))
  1642. return
  1643. dict_elem['offset'] = 'Path'
  1644. dict_elem['offset_value'] = 0.0
  1645. dict_elem['type'] = 'Rough'
  1646. dict_elem['tool_type'] = 'C1'
  1647. dict_elem['data'] = default_data
  1648. new_toolid = len(self.db_tool_dict) + 1
  1649. self.db_tool_dict[str(new_toolid)] = deepcopy(dict_elem)
  1650. # add the new entry to the Tools DB table
  1651. self.update_storage()
  1652. self.build_db_ui()
  1653. # select the last Tree item just added
  1654. nr_items = self.ui.tree_widget.topLevelItemCount()
  1655. if nr_items:
  1656. last_item = self.ui.tree_widget.topLevelItem(nr_items - 1)
  1657. self.ui.tree_widget.setCurrentItem(last_item)
  1658. last_item.setSelected(True)
  1659. self.on_tool_target_changed(val=dict_elem['data']['tool_target'])
  1660. self.app.inform.emit('[success] %s' % _("Tool added to DB."))
  1661. def on_tool_copy(self):
  1662. """
  1663. Copy a selection of Tools in the Tools DB table
  1664. :return:
  1665. """
  1666. new_tool_id = len(self.db_tool_dict)
  1667. for item in self.ui.tree_widget.selectedItems():
  1668. old_tool_id = item.data(0, QtCore.Qt.DisplayRole)
  1669. for toolid, dict_val in list(self.db_tool_dict.items()):
  1670. if int(old_tool_id) == int(toolid):
  1671. new_tool_id += 1
  1672. new_key = str(new_tool_id)
  1673. self.db_tool_dict.update({
  1674. new_key: deepcopy(dict_val)
  1675. })
  1676. self.current_toolid = new_tool_id
  1677. self.update_storage()
  1678. self.build_db_ui()
  1679. # select the last Tree item just added
  1680. nr_items = self.ui.tree_widget.topLevelItemCount()
  1681. if nr_items:
  1682. last_item = self.ui.tree_widget.topLevelItem(nr_items - 1)
  1683. self.ui.tree_widget.setCurrentItem(last_item)
  1684. last_item.setSelected(True)
  1685. self.on_tools_db_edited()
  1686. self.app.inform.emit('[success] %s' % _("Tool copied from Tools DB."))
  1687. def on_tool_delete(self):
  1688. """
  1689. Delete a selection of Tools in the Tools DB table
  1690. :return:
  1691. """
  1692. for item in self.ui.tree_widget.selectedItems():
  1693. toolname_to_remove = item.data(0, QtCore.Qt.DisplayRole)
  1694. for toolid, dict_val in list(self.db_tool_dict.items()):
  1695. if int(toolname_to_remove) == int(toolid):
  1696. # remove from the storage
  1697. self.db_tool_dict.pop(toolid, None)
  1698. self.current_toolid -= 1
  1699. self.update_storage()
  1700. self.build_db_ui()
  1701. # select the first Tree item
  1702. nr_items = self.ui.tree_widget.topLevelItemCount()
  1703. if nr_items:
  1704. first_item = self.ui.tree_widget.topLevelItem(0)
  1705. self.ui.tree_widget.setCurrentItem(first_item)
  1706. first_item.setSelected(True)
  1707. self.app.inform.emit('[success] %s' % _("Tool removed from Tools DB."))
  1708. def on_export_tools_db_file(self):
  1709. self.app.defaults.report_usage("on_export_tools_db_file")
  1710. self.app.log.debug("on_export_tools_db_file()")
  1711. date = str(datetime.today()).rpartition('.')[0]
  1712. date = ''.join(c for c in date if c not in ':-')
  1713. date = date.replace(' ', '_')
  1714. filter__ = "Text File (*.TXT);;All Files (*.*)"
  1715. filename, _f = FCFileSaveDialog.get_saved_filename(
  1716. caption=_("Export Tools Database"),
  1717. directory='{l_save}/FlatCAM_{n}_{date}'.format(l_save=str(self.app.get_last_save_folder()),
  1718. n=_("Tools_Database"),
  1719. date=date),
  1720. ext_filter=filter__)
  1721. filename = str(filename)
  1722. if filename == "":
  1723. self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled."))
  1724. return
  1725. else:
  1726. try:
  1727. f = open(filename, 'w')
  1728. f.close()
  1729. except PermissionError:
  1730. self.app.inform.emit('[WARNING] %s' %
  1731. _("Permission denied, saving not possible.\n"
  1732. "Most likely another app is holding the file open and not accessible."))
  1733. return
  1734. except IOError:
  1735. self.app.log.debug('Creating a new Tools DB file ...')
  1736. f = open(filename, 'w')
  1737. f.close()
  1738. except Exception:
  1739. e = sys.exc_info()[0]
  1740. self.app.log.error("Could not load Tools DB file.")
  1741. self.app.log.error(str(e))
  1742. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Could not load Tools DB file."))
  1743. return
  1744. # Save update options
  1745. try:
  1746. # Save Tools DB in a file
  1747. try:
  1748. with open(filename, "w") as f:
  1749. json.dump(self.db_tool_dict, f, default=to_dict, indent=2)
  1750. except Exception as e:
  1751. self.app.log.debug("App.on_save_tools_db() --> %s" % str(e))
  1752. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  1753. return
  1754. except Exception:
  1755. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  1756. return
  1757. self.app.inform.emit('[success] %s: %s' % (_("Exported Tools DB to"), filename))
  1758. def on_import_tools_db_file(self):
  1759. self.app.defaults.report_usage("on_import_tools_db_file")
  1760. self.app.log.debug("on_import_tools_db_file()")
  1761. filter__ = "Text File (*.TXT);;All Files (*.*)"
  1762. filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Tools DB"), filter=filter__)
  1763. if filename == "":
  1764. self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled."))
  1765. else:
  1766. try:
  1767. with open(filename) as f:
  1768. tools_in_db = f.read()
  1769. except IOError:
  1770. self.app.log.error("Could not load Tools DB file.")
  1771. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Could not load Tools DB file."))
  1772. return
  1773. try:
  1774. self.db_tool_dict = json.loads(tools_in_db)
  1775. except Exception:
  1776. e = sys.exc_info()[0]
  1777. self.app.log.error(str(e))
  1778. self.app.inform.emit('[ERROR] %s' % _("Failed to parse Tools DB file."))
  1779. return
  1780. self.app.inform.emit('[success] %s: %s' % (_("Loaded Tools DB from"), filename))
  1781. self.build_db_ui()
  1782. self.update_storage()
  1783. def on_save_tools_db(self, silent=False):
  1784. self.app.log.debug("ToolsDB.on_save_button() --> Saving Tools Database to file.")
  1785. filename = self.app.tools_database_path()
  1786. # Preferences save, update the color of the Tools DB Tab text
  1787. for idx in range(self.app_ui.plot_tab_area.count()):
  1788. if self.app_ui.plot_tab_area.tabText(idx) == _("Tools Database"):
  1789. self.app_ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('black'))
  1790. self.ui.save_db_btn.setStyleSheet("")
  1791. # clean the dictionary and leave only keys of interest
  1792. for tool_id in self.db_tool_dict.keys():
  1793. if self.db_tool_dict[tool_id]['data']['tool_target'] != _('General'):
  1794. continue
  1795. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('Milling'):
  1796. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1797. if str(k).startswith('tools_'):
  1798. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1799. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('Drilling'):
  1800. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1801. if str(k).startswith('tools_'):
  1802. if str(k).startswith('tools_drill') or str(k).startswith('tools_mill'):
  1803. pass
  1804. else:
  1805. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1806. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('Isolation'):
  1807. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1808. if str(k).startswith('tools_'):
  1809. if str(k).startswith('tools_iso') or str(k).startswith('tools_mill'):
  1810. pass
  1811. else:
  1812. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1813. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('Paint'):
  1814. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1815. if str(k).startswith('tools_'):
  1816. if str(k).startswith('tools_paint') or str(k).startswith('tools_mill'):
  1817. pass
  1818. else:
  1819. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1820. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('NCC'):
  1821. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1822. if str(k).startswith('tools_'):
  1823. if str(k).startswith('tools_ncc') or str(k).startswith('tools_mill'):
  1824. pass
  1825. else:
  1826. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1827. if self.db_tool_dict[tool_id]['data']['tool_target'] == _('Cutout'):
  1828. for k in list(self.db_tool_dict[tool_id]['data'].keys()):
  1829. if str(k).startswith('tools_'):
  1830. if str(k).startswith('tools_cutout') or str(k).startswith('tools_mill'):
  1831. pass
  1832. else:
  1833. self.db_tool_dict[tool_id]['data'].pop(k, None)
  1834. # Save Tools DB in a file
  1835. try:
  1836. f = open(filename, "w")
  1837. json.dump(self.db_tool_dict, f, default=to_dict, indent=2)
  1838. f.close()
  1839. except Exception as e:
  1840. self.app.log.debug("ToolsDB.on_save_tools_db() --> %s" % str(e))
  1841. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  1842. return
  1843. if not silent:
  1844. self.app.inform.emit('[success] %s' % _("Saved Tools DB."))
  1845. def on_save_db_btn_click(self):
  1846. self.app.tools_db_changed_flag = False
  1847. self.on_save_tools_db()
  1848. def on_calculate_tooldia(self):
  1849. if self.ui.mill_shape_combo.get_value() == 'V':
  1850. tip_dia = float(self.ui.mill_vdia_entry.get_value())
  1851. half_tip_angle = float(self.ui.mill_vangle_entry.get_value()) / 2.0
  1852. cut_z = float(self.ui.mill_cutz_entry.get_value())
  1853. cut_z = -cut_z if cut_z < 0 else cut_z
  1854. # calculated tool diameter so the cut_z parameter is obeyed
  1855. tool_dia = tip_dia + (2 * cut_z * math.tan(math.radians(half_tip_angle)))
  1856. self.ui.dia_entry.set_value(tool_dia)
  1857. def ui_connect(self):
  1858. # make sure that we don't make multiple connections to the widgets
  1859. self.ui_disconnect()
  1860. self.ui.name_entry.editingFinished.connect(self.update_tree_name)
  1861. for key in self.form_fields:
  1862. wdg = self.form_fields[key]
  1863. # FCEntry
  1864. if isinstance(wdg, FCEntry):
  1865. wdg.textChanged.connect(self.update_storage)
  1866. # ComboBox
  1867. if isinstance(wdg, FCComboBox):
  1868. wdg.currentIndexChanged.connect(self.update_storage)
  1869. # CheckBox
  1870. if isinstance(wdg, FCCheckBox):
  1871. wdg.toggled.connect(self.update_storage)
  1872. # FCRadio
  1873. if isinstance(wdg, RadioSet):
  1874. wdg.activated_custom.connect(self.update_storage)
  1875. # SpinBox, DoubleSpinBox
  1876. if isinstance(wdg, FCSpinner) or isinstance(wdg, FCDoubleSpinner):
  1877. wdg.valueChanged.connect(self.update_storage)
  1878. # connect the calculate tooldia method to the controls
  1879. # if the tool shape is 'V' the tool dia will be calculated to obey Cut Z parameter
  1880. self.ui.mill_shape_combo.currentIndexChanged.connect(self.on_calculate_tooldia)
  1881. self.ui.mill_cutz_entry.valueChanged.connect(self.on_calculate_tooldia)
  1882. self.ui.mill_vdia_entry.valueChanged.connect(self.on_calculate_tooldia)
  1883. self.ui.mill_vangle_entry.valueChanged.connect(self.on_calculate_tooldia)
  1884. def ui_disconnect(self):
  1885. try:
  1886. self.ui.name_entry.editingFinished.disconnect(self.update_tree_name)
  1887. except (TypeError, AttributeError):
  1888. pass
  1889. try:
  1890. self.ui.mill_shape_combo.currentIndexChanged.disconnect(self.on_calculate_tooldia)
  1891. except (TypeError, AttributeError):
  1892. pass
  1893. try:
  1894. self.ui.mill_cutz_entry.valueChanged.disconnect(self.on_calculate_tooldia)
  1895. except (TypeError, AttributeError):
  1896. pass
  1897. try:
  1898. self.ui.mill_vdia_entry.valueChanged.disconnect(self.on_calculate_tooldia)
  1899. except (TypeError, AttributeError):
  1900. pass
  1901. try:
  1902. self.ui.mill_vangle_entry.valueChanged.disconnect(self.on_calculate_tooldia)
  1903. except (TypeError, AttributeError):
  1904. pass
  1905. for key in self.form_fields:
  1906. wdg = self.form_fields[key]
  1907. # FCEntry
  1908. if isinstance(wdg, FCEntry):
  1909. try:
  1910. wdg.textChanged.disconnect(self.update_storage)
  1911. except (TypeError, AttributeError):
  1912. pass
  1913. # ComboBox
  1914. if isinstance(wdg, FCComboBox):
  1915. try:
  1916. wdg.currentIndexChanged.disconnect(self.update_storage)
  1917. except (TypeError, AttributeError):
  1918. pass
  1919. # CheckBox
  1920. if isinstance(wdg, FCCheckBox):
  1921. try:
  1922. wdg.toggled.disconnect(self.update_storage)
  1923. except (TypeError, AttributeError):
  1924. pass
  1925. # FCRadio
  1926. if isinstance(wdg, RadioSet):
  1927. try:
  1928. wdg.activated_custom.disconnect(self.update_storage)
  1929. except (TypeError, AttributeError):
  1930. pass
  1931. # SpinBox, DoubleSpinBox
  1932. if isinstance(wdg, FCSpinner) or isinstance(wdg, FCDoubleSpinner):
  1933. try:
  1934. wdg.valueChanged.disconnect(self.update_storage)
  1935. except (TypeError, AttributeError):
  1936. pass
  1937. def update_tree_name(self):
  1938. val = self.ui.name_entry.get_value()
  1939. item = self.ui.tree_widget.currentItem()
  1940. if item is None:
  1941. return
  1942. # I'm setting the value for the second column (designated by 1) because first column holds the ID
  1943. # and second column holds the Name (this behavior is set in the build_ui method)
  1944. item.setData(1, QtCore.Qt.DisplayRole, val)
  1945. def update_storage(self):
  1946. """
  1947. Update the dictionary that is the storage of the tools 'database'
  1948. :return:
  1949. """
  1950. tool_id = str(self.current_toolid)
  1951. try:
  1952. wdg = self.sender()
  1953. assert isinstance(wdg, QtWidgets.QWidget) or isinstance(wdg, QtWidgets.QAction), \
  1954. "Expected a QWidget got %s" % type(wdg)
  1955. if wdg is None:
  1956. return
  1957. if isinstance(wdg, FCButton) or isinstance(wdg, QtWidgets.QAction):
  1958. # this is called when adding a new tool; no need to run the update below since that section is for
  1959. # when editing a tool
  1960. self.on_tools_db_edited()
  1961. return
  1962. wdg_name = wdg.objectName()
  1963. val = wdg.get_value()
  1964. except AttributeError as err:
  1965. self.app.log.debug("ToolsDB2.update_storage() -> %s" % str(err))
  1966. return
  1967. # #############################################################################################################
  1968. # #############################################################################################################
  1969. # ################ EDITING PARAMETERS IN A TOOL SECTION
  1970. # #############################################################################################################
  1971. # #############################################################################################################
  1972. # #############################################################################################################
  1973. # this might change in the future; it makes sense to change values at once for all tools
  1974. # for now change values only for one tool at once
  1975. sel_rows = []
  1976. for item in self.ui.tree_widget.selectedItems():
  1977. sel_rows.append(item.data(0, QtCore.Qt.DisplayRole))
  1978. len_sel_rows = len(sel_rows)
  1979. if len_sel_rows > 1:
  1980. msg = '[ERROR_NOTCL] %s: %s' % \
  1981. (_("To change tool properties select only one tool. Tools currently selected"), str(len_sel_rows))
  1982. self.app.inform.emit(msg)
  1983. old_value = self.db_tool_dict[tool_id]['data'][self.name2option[wdg_name]]
  1984. wdg.set_value(old_value)
  1985. wdg.clearFocus()
  1986. return
  1987. # #############################################################################################################
  1988. if wdg_name == "gdb_name":
  1989. self.db_tool_dict[tool_id]['name'] = val
  1990. elif wdg_name == "gdb_dia":
  1991. self.db_tool_dict[tool_id]['tooldia'] = val
  1992. elif wdg_name == "gdb_tool_offset":
  1993. self.db_tool_dict[tool_id]['offset'] = val
  1994. elif wdg_name == "gdb_custom_offset":
  1995. self.db_tool_dict[tool_id]['offset_value'] = val
  1996. elif wdg_name == "gdb_type":
  1997. self.db_tool_dict[tool_id]['type'] = val
  1998. elif wdg_name == "gdb_shape":
  1999. self.db_tool_dict[tool_id]['tool_type'] = val
  2000. else:
  2001. # Milling Tool
  2002. if wdg_name == "gdb_tool_target":
  2003. self.db_tool_dict[tool_id]['data']['tool_target'] = val
  2004. elif wdg_name == "gdb_tol_min":
  2005. self.db_tool_dict[tool_id]['data']['tol_min'] = val
  2006. elif wdg_name == "gdb_tol_max":
  2007. self.db_tool_dict[tool_id]['data']['tol_max'] = val
  2008. elif wdg_name == "gdb_cutz":
  2009. self.db_tool_dict[tool_id]['data']['cutz'] = val
  2010. elif wdg_name == "gdb_multidepth":
  2011. self.db_tool_dict[tool_id]['data']['multidepth'] = val
  2012. elif wdg_name == "gdb_multidepth_entry":
  2013. self.db_tool_dict[tool_id]['data']['depthperpass'] = val
  2014. elif wdg_name == "gdb_travelz":
  2015. self.db_tool_dict[tool_id]['data']['travelz'] = val
  2016. elif wdg_name == "gdb_frxy":
  2017. self.db_tool_dict[tool_id]['data']['feedrate'] = val
  2018. elif wdg_name == "gdb_frz":
  2019. self.db_tool_dict[tool_id]['data']['feedrate_z'] = val
  2020. elif wdg_name == "gdb_spindle":
  2021. self.db_tool_dict[tool_id]['data']['spindlespeed'] = val
  2022. elif wdg_name == "gdb_dwell":
  2023. self.db_tool_dict[tool_id]['data']['dwell'] = val
  2024. elif wdg_name == "gdb_dwelltime":
  2025. self.db_tool_dict[tool_id]['data']['dwelltime'] = val
  2026. elif wdg_name == "gdb_vdia":
  2027. self.db_tool_dict[tool_id]['data']['vtipdia'] = val
  2028. elif wdg_name == "gdb_vangle":
  2029. self.db_tool_dict[tool_id]['data']['vtipangle'] = val
  2030. elif wdg_name == "gdb_frapids":
  2031. self.db_tool_dict[tool_id]['data']['feedrate_rapid'] = val
  2032. elif wdg_name == "gdb_ecut":
  2033. self.db_tool_dict[tool_id]['data']['extracut'] = val
  2034. elif wdg_name == "gdb_ecut_length":
  2035. self.db_tool_dict[tool_id]['data']['extracut_length'] = val
  2036. # NCC Tool
  2037. elif wdg_name == "gdb_n_operation":
  2038. self.db_tool_dict[tool_id]['data']['tools_ncc_operation'] = val
  2039. elif wdg_name == "gdb_n_overlap":
  2040. self.db_tool_dict[tool_id]['data']['tools_ncc_overlap'] = val
  2041. elif wdg_name == "gdb_n_margin":
  2042. self.db_tool_dict[tool_id]['data']['tools_ncc_margin'] = val
  2043. elif wdg_name == "gdb_n_method":
  2044. self.db_tool_dict[tool_id]['data']['tools_ncc_method'] = val
  2045. elif wdg_name == "gdb_n_connect":
  2046. self.db_tool_dict[tool_id]['data']['tools_ncc_connect'] = val
  2047. elif wdg_name == "gdb_n_contour":
  2048. self.db_tool_dict[tool_id]['data']['tools_ncc_contour'] = val
  2049. elif wdg_name == "gdb_n_offset":
  2050. self.db_tool_dict[tool_id]['data']['tools_ncc_offset_choice'] = val
  2051. elif wdg_name == "gdb_n_offset_value":
  2052. self.db_tool_dict[tool_id]['data']['tools_ncc_offset_value'] = val
  2053. elif wdg_name == "gdb_n_milling_type":
  2054. self.db_tool_dict[tool_id]['data']['tools_ncc_milling_type'] = val
  2055. # Paint Tool
  2056. elif wdg_name == "gdb_p_overlap":
  2057. self.db_tool_dict[tool_id]['data']['tools_paint_overlap'] = val
  2058. elif wdg_name == "gdb_p_offset":
  2059. self.db_tool_dict[tool_id]['data']['tools_paint_offset'] = val
  2060. elif wdg_name == "gdb_p_method":
  2061. self.db_tool_dict[tool_id]['data']['tools_paint_method'] = val
  2062. elif wdg_name == "gdb_p_connect":
  2063. self.db_tool_dict[tool_id]['data']['tools_paint_connect'] = val
  2064. elif wdg_name == "gdb_p_contour":
  2065. self.db_tool_dict[tool_id]['data']['tools_paint_contour'] = val
  2066. # Isolation Tool
  2067. elif wdg_name == "gdb_i_passes":
  2068. self.db_tool_dict[tool_id]['data']['tools_iso_passes'] = val
  2069. elif wdg_name == "gdb_i_overlap":
  2070. self.db_tool_dict[tool_id]['data']['tools_iso_overlap'] = val
  2071. elif wdg_name == "gdb_i_milling_type":
  2072. self.db_tool_dict[tool_id]['data']['tools_iso_milling_type'] = val
  2073. elif wdg_name == "gdb_i_follow":
  2074. self.db_tool_dict[tool_id]['data']['tools_iso_follow'] = val
  2075. elif wdg_name == "gdb_i_iso_type":
  2076. self.db_tool_dict[tool_id]['data']['tools_iso_isotype'] = val
  2077. # Drilling Tool
  2078. elif wdg_name == "gdb_e_cutz":
  2079. self.db_tool_dict[tool_id]['data']['tools_drill_cutz'] = val
  2080. elif wdg_name == "gdb_e_multidepth":
  2081. self.db_tool_dict[tool_id]['data']['tools_drill_multidepth'] = val
  2082. elif wdg_name == "gdb_e_depthperpass":
  2083. self.db_tool_dict[tool_id]['data']['tools_drill_depthperpass'] = val
  2084. elif wdg_name == "gdb_e_travelz":
  2085. self.db_tool_dict[tool_id]['data']['tools_drill_travelz'] = val
  2086. elif wdg_name == "gdb_e_feedratez":
  2087. self.db_tool_dict[tool_id]['data']['tools_drill_feedrate_z'] = val
  2088. elif wdg_name == "gdb_e_fr_rapid":
  2089. self.db_tool_dict[tool_id]['data']['tools_drill_feedrate_rapid'] = val
  2090. elif wdg_name == "gdb_e_spindlespeed":
  2091. self.db_tool_dict[tool_id]['data']['tools_drill_spindlespeed'] = val
  2092. elif wdg_name == "gdb_e_dwell":
  2093. self.db_tool_dict[tool_id]['data']['tools_drill_dwell'] = val
  2094. elif wdg_name == "gdb_e_dwelltime":
  2095. self.db_tool_dict[tool_id]['data']['tools_drill_dwelltime'] = val
  2096. elif wdg_name == "gdb_e_offset":
  2097. self.db_tool_dict[tool_id]['data']['tools_drill_offset'] = val
  2098. elif wdg_name == "gdb_e_drill_slots":
  2099. self.db_tool_dict[tool_id]['data']['tools_drill_drill_slots'] = val
  2100. elif wdg_name == "gdb_e_drill_slots_over":
  2101. self.db_tool_dict[tool_id]['data']['tools_drill_drill_overlap'] = val
  2102. elif wdg_name == "gdb_e_drill_last_drill":
  2103. self.db_tool_dict[tool_id]['data']['tools_drill_last_drill'] = val
  2104. # Cutout Tool
  2105. elif wdg_name == "gdb_ct_margin":
  2106. self.db_tool_dict[tool_id]['data']['tools_cutout_margin'] = val
  2107. elif wdg_name == "gdb_ct_gapsize":
  2108. self.db_tool_dict[tool_id]['data']['tools_cutout_gapsize'] = val
  2109. elif wdg_name == "gdb_ct_gaps":
  2110. self.db_tool_dict[tool_id]['data']['tools_cutout_gaps_ff'] = val
  2111. elif wdg_name == "gdb_ct_convex":
  2112. self.db_tool_dict[tool_id]['data']['tools_cutout_convexshape'] = val
  2113. elif wdg_name == "gdb_ct_gap_type":
  2114. self.db_tool_dict[tool_id]['data']['tools_cutout_gap_type'] = val
  2115. elif wdg_name == "gdb_ct_gap_depth":
  2116. self.db_tool_dict[tool_id]['data']['tools_cutout_gap_depth'] = val
  2117. elif wdg_name == "gdb_ct_mb_dia":
  2118. self.db_tool_dict[tool_id]['data']['tools_cutout_mb_dia'] = val
  2119. elif wdg_name == "gdb_ct_mb_spacing":
  2120. self.db_tool_dict[tool_id]['data']['tools_cutout_mb_spacing'] = val
  2121. self.on_tools_db_edited()
  2122. def on_tool_requested_from_app(self):
  2123. if not self.ui.tree_widget.selectedItems():
  2124. self.app.inform.emit('[WARNING_NOTCL] %s...' % _("No Tool/row selected in the Tools Database table"))
  2125. return
  2126. if not self.db_tool_dict:
  2127. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Tools DB empty."))
  2128. return
  2129. for item in self.ui.tree_widget.selectedItems():
  2130. tool_uid = item.data(0, QtCore.Qt.DisplayRole)
  2131. for key in self.db_tool_dict.keys():
  2132. if str(key) == str(tool_uid):
  2133. selected_tool = self.db_tool_dict[key]
  2134. self.on_tool_request(tool=selected_tool)
  2135. def on_tools_db_edited(self, silent=None):
  2136. """
  2137. Executed whenever a tool is edited in Tools Database.
  2138. Will color the text of the Tools Database tab to Red color.
  2139. :return:
  2140. """
  2141. for idx in range(self.app.ui.plot_tab_area.count()):
  2142. if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
  2143. self.app.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('red'))
  2144. self.ui.save_db_btn.setStyleSheet("QPushButton {color: red;}")
  2145. self.tools_db_changed_flag = True
  2146. if silent is None:
  2147. msg = '[WARNING_NOTCL] %s' % _("Tools in Tools Database edited but not saved.")
  2148. self.app.inform[str, bool].emit(msg, False)
  2149. def on_cancel_tool(self):
  2150. for idx in range(self.app_ui.plot_tab_area.count()):
  2151. if self.app_ui.plot_tab_area.tabText(idx) == _("Tools Database"):
  2152. wdg = self.app_ui.plot_tab_area.widget(idx)
  2153. wdg.deleteLater()
  2154. self.app_ui.plot_tab_area.removeTab(idx)
  2155. self.app.inform.emit('%s' % _("Cancelled adding tool from DB."))
  2156. # def resize_new_tool_table_widget(self, min_size, max_size):
  2157. # """
  2158. # Resize the table widget responsible for adding new tool in the Tool Database
  2159. #
  2160. # :param min_size: passed by rangeChanged signal or the self.new_tool_table_widget.horizontalScrollBar()
  2161. # :param max_size: passed by rangeChanged signal or the self.new_tool_table_widget.horizontalScrollBar()
  2162. # :return:
  2163. # """
  2164. # t_height = self.t_height
  2165. # if max_size > min_size:
  2166. # t_height = self.t_height + self.new_tool_table_widget.verticalScrollBar().height()
  2167. #
  2168. # self.new_tool_table_widget.setMaximumHeight(t_height)
  2169. def closeEvent(self, QCloseEvent):
  2170. super().closeEvent(QCloseEvent)
  2171. # class ToolsDB(QtWidgets.QWidget):
  2172. #
  2173. # mark_tools_rows = QtCore.pyqtSignal()
  2174. #
  2175. # def __init__(self, app, callback_on_edited, callback_on_tool_request, parent=None):
  2176. # super(ToolsDB, self).__init__(parent)
  2177. #
  2178. # self.app = app
  2179. # self.decimals = 4
  2180. # self.callback_app = callback_on_edited
  2181. #
  2182. # self.on_tool_request = callback_on_tool_request
  2183. #
  2184. # self.offset_item_options = ["Path", "In", "Out", "Custom"]
  2185. # self.type_item_options = ["Iso", "Rough", "Finish"]
  2186. # self.tool_type_item_options = ["C1", "C2", "C3", "C4", "B", "V"]
  2187. #
  2188. # '''
  2189. # dict to hold all the tools in the Tools DB
  2190. # format:
  2191. # {
  2192. # tool_id: {
  2193. # 'name': 'new_tool'
  2194. # 'tooldia': self.app.defaults["geometry_cnctooldia"]
  2195. # 'offset': 'Path'
  2196. # 'offset_value': 0.0
  2197. # 'type': _('Rough'),
  2198. # 'tool_type': 'C1'
  2199. # 'data': dict()
  2200. # }
  2201. # }
  2202. # '''
  2203. # self.db_tool_dict = {}
  2204. #
  2205. # # layouts
  2206. # layout = QtWidgets.QVBoxLayout()
  2207. # self.setLayout(layout)
  2208. #
  2209. # table_hlay = QtWidgets.QHBoxLayout()
  2210. # layout.addLayout(table_hlay)
  2211. #
  2212. # self.table_widget = FCTable(drag_drop=True)
  2213. # self.table_widget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
  2214. # table_hlay.addWidget(self.table_widget)
  2215. #
  2216. # # set the number of columns and the headers tool tips
  2217. # self.configure_table()
  2218. #
  2219. # # pal = QtGui.QPalette()
  2220. # # pal.setColor(QtGui.QPalette.Background, Qt.white)
  2221. #
  2222. # # New Bookmark
  2223. # new_vlay = QtWidgets.QVBoxLayout()
  2224. # layout.addLayout(new_vlay)
  2225. #
  2226. # # new_tool_lbl = FCLabel('<b>%s</b>' % _("New Tool"))
  2227. # # new_vlay.addWidget(new_tool_lbl, alignment=QtCore.Qt.AlignBottom)
  2228. #
  2229. # self.buttons_frame = QtWidgets.QFrame()
  2230. # self.buttons_frame.setContentsMargins(0, 0, 0, 0)
  2231. # layout.addWidget(self.buttons_frame)
  2232. # self.buttons_box = QtWidgets.QHBoxLayout()
  2233. # self.buttons_box.setContentsMargins(0, 0, 0, 0)
  2234. # self.buttons_frame.setLayout(self.buttons_box)
  2235. # self.buttons_frame.show()
  2236. #
  2237. # add_entry_btn = FCButton(_("Add Geometry Tool in DB"))
  2238. # add_entry_btn.setToolTip(
  2239. # _("Add a new tool in the Tools Database.\n"
  2240. # "It will be used in the Geometry UI.\n"
  2241. # "You can edit it after it is added.")
  2242. # )
  2243. # self.buttons_box.addWidget(add_entry_btn)
  2244. #
  2245. # # add_fct_entry_btn = FCButton(_("Add Paint/NCC Tool in DB"))
  2246. # # add_fct_entry_btn.setToolTip(
  2247. # # _("Add a new tool in the Tools Database.\n"
  2248. # # "It will be used in the Paint/NCC Tools UI.\n"
  2249. # # "You can edit it after it is added.")
  2250. # # )
  2251. # # self.buttons_box.addWidget(add_fct_entry_btn)
  2252. #
  2253. # remove_entry_btn = FCButton(_("Delete Tool from DB"))
  2254. # remove_entry_btn.setToolTip(
  2255. # _("Remove a selection of tools in the Tools Database.")
  2256. # )
  2257. # self.buttons_box.addWidget(remove_entry_btn)
  2258. #
  2259. # export_db_btn = FCButton(_("Export DB"))
  2260. # export_db_btn.setToolTip(
  2261. # _("Save the Tools Database to a custom text file.")
  2262. # )
  2263. # self.buttons_box.addWidget(export_db_btn)
  2264. #
  2265. # import_db_btn = FCButton(_("Import DB"))
  2266. # import_db_btn.setToolTip(
  2267. # _("Load the Tools Database information's from a custom text file.")
  2268. # )
  2269. # self.buttons_box.addWidget(import_db_btn)
  2270. #
  2271. # self.add_tool_from_db = FCButton(_("Transfer the Tool"))
  2272. # self.add_tool_from_db.setToolTip(
  2273. # _("Add a new tool in the Tools Table of the\n"
  2274. # "active Geometry object after selecting a tool\n"
  2275. # "in the Tools Database.")
  2276. # )
  2277. # self.add_tool_from_db.hide()
  2278. #
  2279. # self.cancel_tool_from_db = FCButton(_("Cancel"))
  2280. # self.cancel_tool_from_db.hide()
  2281. #
  2282. # hlay = QtWidgets.QHBoxLayout()
  2283. # layout.addLayout(hlay)
  2284. # hlay.addWidget(self.add_tool_from_db)
  2285. # hlay.addWidget(self.cancel_tool_from_db)
  2286. # hlay.addStretch()
  2287. #
  2288. # # ##############################################################################
  2289. # # ######################## SIGNALS #############################################
  2290. # # ##############################################################################
  2291. #
  2292. # add_entry_btn.clicked.connect(self.on_tool_add)
  2293. # remove_entry_btn.clicked.connect(self.on_tool_delete)
  2294. # export_db_btn.clicked.connect(self.on_export_tools_db_file)
  2295. # import_db_btn.clicked.connect(self.on_import_tools_db_file)
  2296. # # closebtn.clicked.connect(self.accept)
  2297. #
  2298. # self.add_tool_from_db.clicked.connect(self.on_tool_requested_from_app)
  2299. # self.cancel_tool_from_db.clicked.connect(self.on_cancel_tool)
  2300. #
  2301. # self.setup_db_ui()
  2302. #
  2303. # def configure_table(self):
  2304. # self.table_widget.setColumnCount(27)
  2305. # # self.table_widget.setColumnWidth(0, 20)
  2306. # self.table_widget.setHorizontalHeaderLabels(
  2307. # [
  2308. # '#',
  2309. # _("Tool Name"),
  2310. # _("Tool Dia"),
  2311. # _("Tool Offset"),
  2312. # _("Custom Offset"),
  2313. # _("Tool Type"),
  2314. # _("Tool Shape"),
  2315. # _("Cut Z"),
  2316. # _("MultiDepth"),
  2317. # _("DPP"),
  2318. # _("V-Dia"),
  2319. # _("V-Angle"),
  2320. # _("Travel Z"),
  2321. # _("FR"),
  2322. # _("FR Z"),
  2323. # _("FR Rapids"),
  2324. # _("Spindle Speed"),
  2325. # _("Dwell"),
  2326. # _("Dwelltime"),
  2327. # _("Preprocessor"),
  2328. # _("ExtraCut"),
  2329. # _("E-Cut Length"),
  2330. # _("Toolchange"),
  2331. # _("Toolchange XY"),
  2332. # _("Toolchange Z"),
  2333. # _("Start Z"),
  2334. # _("End Z"),
  2335. # ]
  2336. # )
  2337. # self.table_widget.horizontalHeaderItem(0).setToolTip(
  2338. # _("Tool Index."))
  2339. # self.table_widget.horizontalHeaderItem(1).setToolTip(
  2340. # _("Tool name.\n"
  2341. # "This is not used in the app, it's function\n"
  2342. # "is to serve as a note for the user."))
  2343. # self.table_widget.horizontalHeaderItem(2).setToolTip(
  2344. # _("Tool Diameter."))
  2345. # self.table_widget.horizontalHeaderItem(3).setToolTip(
  2346. # _("Tool Offset.\n"
  2347. # "Can be of a few types:\n"
  2348. # "Path = zero offset\n"
  2349. # "In = offset inside by half of tool diameter\n"
  2350. # "Out = offset outside by half of tool diameter\n"
  2351. # "Custom = custom offset using the Custom Offset value"))
  2352. # self.table_widget.horizontalHeaderItem(4).setToolTip(
  2353. # _("Custom Offset.\n"
  2354. # "A value to be used as offset from the current path."))
  2355. # self.table_widget.horizontalHeaderItem(5).setToolTip(
  2356. # _("Tool Type.\n"
  2357. # "Can be:\n"
  2358. # "Iso = isolation cut\n"
  2359. # "Rough = rough cut, low feedrate, multiple passes\n"
  2360. # "Finish = finishing cut, high feedrate"))
  2361. # self.table_widget.horizontalHeaderItem(6).setToolTip(
  2362. # _("Tool Shape. \n"
  2363. # "Can be:\n"
  2364. # "C1 ... C4 = circular tool with x flutes\n"
  2365. # "B = ball tip milling tool\n"
  2366. # "V = v-shape milling tool"))
  2367. # self.table_widget.horizontalHeaderItem(7).setToolTip(
  2368. # _("Cutting Depth.\n"
  2369. # "The depth at which to cut into material."))
  2370. # self.table_widget.horizontalHeaderItem(8).setToolTip(
  2371. # _("Multi Depth.\n"
  2372. # "Selecting this will allow cutting in multiple passes,\n"
  2373. # "each pass adding a DPP parameter depth."))
  2374. # self.table_widget.horizontalHeaderItem(9).setToolTip(
  2375. # _("DPP. Depth per Pass.\n"
  2376. # "The value used to cut into material on each pass."))
  2377. # self.table_widget.horizontalHeaderItem(10).setToolTip(
  2378. # _("V-Dia.\n"
  2379. # "Diameter of the tip for V-Shape Tools."))
  2380. # self.table_widget.horizontalHeaderItem(11).setToolTip(
  2381. # _("V-Agle.\n"
  2382. # "Angle at the tip for the V-Shape Tools."))
  2383. # self.table_widget.horizontalHeaderItem(12).setToolTip(
  2384. # _("Clearance Height.\n"
  2385. # "Height at which the milling bit will travel between cuts,\n"
  2386. # "above the surface of the material, avoiding all fixtures."))
  2387. # self.table_widget.horizontalHeaderItem(13).setToolTip(
  2388. # _("FR. Feedrate\n"
  2389. # "The speed on XY plane used while cutting into material."))
  2390. # self.table_widget.horizontalHeaderItem(14).setToolTip(
  2391. # _("FR Z. Feedrate Z\n"
  2392. # "The speed on Z plane."))
  2393. # self.table_widget.horizontalHeaderItem(15).setToolTip(
  2394. # _("FR Rapids. Feedrate Rapids\n"
  2395. # "Speed used while moving as fast as possible.\n"
  2396. # "This is used only by some devices that can't use\n"
  2397. # "the G0 g-code command. Mostly 3D printers."))
  2398. # self.table_widget.horizontalHeaderItem(16).setToolTip(
  2399. # _("Spindle Speed.\n"
  2400. # "If it's left empty it will not be used.\n"
  2401. # "The speed of the spindle in RPM."))
  2402. # self.table_widget.horizontalHeaderItem(17).setToolTip(
  2403. # _("Dwell.\n"
  2404. # "Check this if a delay is needed to allow\n"
  2405. # "the spindle motor to reach its set speed."))
  2406. # self.table_widget.horizontalHeaderItem(18).setToolTip(
  2407. # _("Dwell Time.\n"
  2408. # "A delay used to allow the motor spindle reach its set speed."))
  2409. # self.table_widget.horizontalHeaderItem(19).setToolTip(
  2410. # _("Preprocessor.\n"
  2411. # "A selection of files that will alter the generated G-code\n"
  2412. # "to fit for a number of use cases."))
  2413. # self.table_widget.horizontalHeaderItem(20).setToolTip(
  2414. # _("Extra Cut.\n"
  2415. # "If checked, after a isolation is finished an extra cut\n"
  2416. # "will be added where the start and end of isolation meet\n"
  2417. # "such as that this point is covered by this extra cut to\n"
  2418. # "ensure a complete isolation."))
  2419. # self.table_widget.horizontalHeaderItem(21).setToolTip(
  2420. # _("Extra Cut length.\n"
  2421. # "If checked, after a isolation is finished an extra cut\n"
  2422. # "will be added where the start and end of isolation meet\n"
  2423. # "such as that this point is covered by this extra cut to\n"
  2424. # "ensure a complete isolation. This is the length of\n"
  2425. # "the extra cut."))
  2426. # self.table_widget.horizontalHeaderItem(22).setToolTip(
  2427. # _("Toolchange.\n"
  2428. # "It will create a toolchange event.\n"
  2429. # "The kind of toolchange is determined by\n"
  2430. # "the preprocessor file."))
  2431. # self.table_widget.horizontalHeaderItem(23).setToolTip(
  2432. # _("Toolchange XY.\n"
  2433. # "A set of coordinates in the format (x, y).\n"
  2434. # "Will determine the cartesian position of the point\n"
  2435. # "where the tool change event take place."))
  2436. # self.table_widget.horizontalHeaderItem(24).setToolTip(
  2437. # _("Toolchange Z.\n"
  2438. # "The position on Z plane where the tool change event take place."))
  2439. # self.table_widget.horizontalHeaderItem(25).setToolTip(
  2440. # _("Start Z.\n"
  2441. # "If it's left empty it will not be used.\n"
  2442. # "A position on Z plane to move immediately after job start."))
  2443. # self.table_widget.horizontalHeaderItem(26).setToolTip(
  2444. # _("End Z.\n"
  2445. # "A position on Z plane to move immediately after job stop."))
  2446. #
  2447. # def setup_db_ui(self):
  2448. # filename = self.app.tools_database_path()
  2449. #
  2450. # # load the database tools from the file
  2451. # try:
  2452. # with open(filename) as f:
  2453. # tools = f.read()
  2454. # except IOError:
  2455. # self.app.log.error("Could not load tools DB file.")
  2456. # self.app.inform.emit('[ERROR] %s' % _("Could not load Tools DB file."))
  2457. # return
  2458. #
  2459. # try:
  2460. # self.db_tool_dict = json.loads(tools)
  2461. # except Exception:
  2462. # e = sys.exc_info()[0]
  2463. # self.app.log.error(str(e))
  2464. # self.app.inform.emit('[ERROR] %s' % _("Failed to parse Tools DB file."))
  2465. # return
  2466. #
  2467. # self.app.inform.emit('[success] %s: %s' % (_("Loaded Tools DB from"), filename))
  2468. #
  2469. # self.build_db_ui()
  2470. #
  2471. # self.table_widget.setupContextMenu()
  2472. # self.table_widget.addContextMenu(
  2473. # _("Add to DB"), self.on_tool_add, icon=QtGui.QIcon(self.app.resource_location + "/plus16.png"))
  2474. # self.table_widget.addContextMenu(
  2475. # _("Copy from DB"), self.on_tool_copy, icon=QtGui.QIcon(self.app.resource_location + "/copy16.png"))
  2476. # self.table_widget.addContextMenu(
  2477. # _("Delete from DB"), self.on_tool_delete, icon=QtGui.QIcon(self.app.resource_location + "/delete32.png"))
  2478. #
  2479. # def build_db_ui(self):
  2480. # self.ui_disconnect()
  2481. # self.table_widget.setRowCount(len(self.db_tool_dict))
  2482. #
  2483. # nr_crt = 0
  2484. #
  2485. # for toolid, dict_val in self.db_tool_dict.items():
  2486. # row = nr_crt
  2487. # nr_crt += 1
  2488. #
  2489. # t_name = dict_val['name']
  2490. # try:
  2491. # self.add_tool_table_line(row, name=t_name, widget=self.table_widget, tooldict=dict_val)
  2492. # except Exception as e:
  2493. # self.app.log.debug("ToolDB.build_db_ui.add_tool_table_line() --> %s" % str(e))
  2494. # vertical_header = self.table_widget.verticalHeader()
  2495. # vertical_header.hide()
  2496. #
  2497. # horizontal_header = self.table_widget.horizontalHeader()
  2498. # horizontal_header.setMinimumSectionSize(10)
  2499. # horizontal_header.setDefaultSectionSize(70)
  2500. #
  2501. # self.table_widget.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  2502. # for x in range(27):
  2503. # self.table_widget.resizeColumnToContents(x)
  2504. #
  2505. # horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
  2506. # # horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
  2507. # # horizontal_header.setSectionResizeMode(13, QtWidgets.QHeaderView.Fixed)
  2508. #
  2509. # horizontal_header.resizeSection(0, 20)
  2510. # # horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
  2511. # # horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
  2512. #
  2513. # self.ui_connect()
  2514. #
  2515. # def add_tool_table_line(self, row, name, widget, tooldict):
  2516. # data = tooldict['data']
  2517. #
  2518. # nr_crt = row + 1
  2519. # id_item = QtWidgets.QTableWidgetItem('%d' % int(nr_crt))
  2520. # # id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
  2521. # flags = id_item.flags() & ~QtCore.Qt.ItemIsEditable
  2522. # id_item.setFlags(flags)
  2523. # widget.setItem(row, 0, id_item) # Tool name/id
  2524. #
  2525. # tool_name_item = QtWidgets.QTableWidgetItem(name)
  2526. # widget.setItem(row, 1, tool_name_item)
  2527. #
  2528. # dia_item = FCDoubleSpinner()
  2529. # dia_item.set_precision(self.decimals)
  2530. # dia_item.setSingleStep(0.1)
  2531. # dia_item.set_range(0.0, 9999.9999)
  2532. # dia_item.set_value(float(tooldict['tooldia']))
  2533. # widget.setCellWidget(row, 2, dia_item)
  2534. #
  2535. # tool_offset_item = FCComboBox()
  2536. # for item in self.offset_item_options:
  2537. # tool_offset_item.addItem(item)
  2538. # tool_offset_item.set_value(tooldict['offset'])
  2539. # widget.setCellWidget(row, 3, tool_offset_item)
  2540. #
  2541. # c_offset_item = FCDoubleSpinner()
  2542. # c_offset_item.set_precision(self.decimals)
  2543. # c_offset_item.setSingleStep(0.1)
  2544. # c_offset_item.set_range(-9999.9999, 9999.9999)
  2545. # c_offset_item.set_value(float(tooldict['offset_value']))
  2546. # widget.setCellWidget(row, 4, c_offset_item)
  2547. #
  2548. # tt_item = FCComboBox()
  2549. # for item in self.type_item_options:
  2550. # tt_item.addItem(item)
  2551. # tt_item.set_value(tooldict['type'])
  2552. # widget.setCellWidget(row, 5, tt_item)
  2553. #
  2554. # tshape_item = FCComboBox()
  2555. # for item in self.tool_type_item_options:
  2556. # tshape_item.addItem(item)
  2557. # tshape_item.set_value(tooldict['tool_type'])
  2558. # widget.setCellWidget(row, 6, tshape_item)
  2559. #
  2560. # cutz_item = FCDoubleSpinner()
  2561. # cutz_item.set_precision(self.decimals)
  2562. # cutz_item.setSingleStep(0.1)
  2563. # if self.app.defaults['global_machinist_setting']:
  2564. # cutz_item.set_range(-9999.9999, 9999.9999)
  2565. # else:
  2566. # cutz_item.set_range(-9999.9999, -0.0000)
  2567. #
  2568. # cutz_item.set_value(float(data['cutz']))
  2569. # widget.setCellWidget(row, 7, cutz_item)
  2570. #
  2571. # multidepth_item = FCCheckBox()
  2572. # multidepth_item.set_value(data['multidepth'])
  2573. # widget.setCellWidget(row, 8, multidepth_item)
  2574. #
  2575. # # to make the checkbox centered but it can no longer have it's value accessed - needs a fix using findchild()
  2576. # # multidepth_item = QtWidgets.QWidget()
  2577. # # cb = FCCheckBox()
  2578. # # cb.set_value(data['multidepth'])
  2579. # # qhboxlayout = QtWidgets.QHBoxLayout(multidepth_item)
  2580. # # qhboxlayout.addWidget(cb)
  2581. # # qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
  2582. # # qhboxlayout.setContentsMargins(0, 0, 0, 0)
  2583. # # widget.setCellWidget(row, 8, multidepth_item)
  2584. #
  2585. # depth_per_pass_item = FCDoubleSpinner()
  2586. # depth_per_pass_item.set_precision(self.decimals)
  2587. # depth_per_pass_item.setSingleStep(0.1)
  2588. # depth_per_pass_item.set_range(0.0, 9999.9999)
  2589. # depth_per_pass_item.set_value(float(data['depthperpass']))
  2590. # widget.setCellWidget(row, 9, depth_per_pass_item)
  2591. #
  2592. # vtip_dia_item = FCDoubleSpinner()
  2593. # vtip_dia_item.set_precision(self.decimals)
  2594. # vtip_dia_item.setSingleStep(0.1)
  2595. # vtip_dia_item.set_range(0.0, 9999.9999)
  2596. # vtip_dia_item.set_value(float(data['vtipdia']))
  2597. # widget.setCellWidget(row, 10, vtip_dia_item)
  2598. #
  2599. # vtip_angle_item = FCDoubleSpinner()
  2600. # vtip_angle_item.set_precision(self.decimals)
  2601. # vtip_angle_item.setSingleStep(0.1)
  2602. # vtip_angle_item.set_range(-360.0, 360.0)
  2603. # vtip_angle_item.set_value(float(data['vtipangle']))
  2604. # widget.setCellWidget(row, 11, vtip_angle_item)
  2605. #
  2606. # travelz_item = FCDoubleSpinner()
  2607. # travelz_item.set_precision(self.decimals)
  2608. # travelz_item.setSingleStep(0.1)
  2609. # if self.app.defaults['global_machinist_setting']:
  2610. # travelz_item.set_range(-9999.9999, 9999.9999)
  2611. # else:
  2612. # travelz_item.set_range(0.0000, 9999.9999)
  2613. #
  2614. # travelz_item.set_value(float(data['travelz']))
  2615. # widget.setCellWidget(row, 12, travelz_item)
  2616. #
  2617. # fr_item = FCDoubleSpinner()
  2618. # fr_item.set_precision(self.decimals)
  2619. # fr_item.set_range(0.0, 9999.9999)
  2620. # fr_item.set_value(float(data['feedrate']))
  2621. # widget.setCellWidget(row, 13, fr_item)
  2622. #
  2623. # frz_item = FCDoubleSpinner()
  2624. # frz_item.set_precision(self.decimals)
  2625. # frz_item.set_range(0.0, 9999.9999)
  2626. # frz_item.set_value(float(data['feedrate_z']))
  2627. # widget.setCellWidget(row, 14, frz_item)
  2628. #
  2629. # frrapids_item = FCDoubleSpinner()
  2630. # frrapids_item.set_precision(self.decimals)
  2631. # frrapids_item.set_range(0.0, 9999.9999)
  2632. # frrapids_item.set_value(float(data['feedrate_rapid']))
  2633. # widget.setCellWidget(row, 15, frrapids_item)
  2634. #
  2635. # spindlespeed_item = FCSpinner()
  2636. # spindlespeed_item.set_range(0, 1000000)
  2637. # spindlespeed_item.set_value(int(data['spindlespeed']))
  2638. # spindlespeed_item.set_step(100)
  2639. # widget.setCellWidget(row, 16, spindlespeed_item)
  2640. #
  2641. # dwell_item = FCCheckBox()
  2642. # dwell_item.set_value(data['dwell'])
  2643. # widget.setCellWidget(row, 17, dwell_item)
  2644. #
  2645. # dwelltime_item = FCDoubleSpinner()
  2646. # dwelltime_item.set_precision(self.decimals)
  2647. # dwelltime_item.set_range(0.0000, 9999.9999)
  2648. # dwelltime_item.set_value(float(data['dwelltime']))
  2649. # widget.setCellWidget(row, 18, dwelltime_item)
  2650. #
  2651. # pp_item = FCComboBox()
  2652. # for item in self.app.preprocessors:
  2653. # pp_item.addItem(item)
  2654. # pp_item.set_value(data['ppname_g'])
  2655. # widget.setCellWidget(row, 19, pp_item)
  2656. #
  2657. # ecut_item = FCCheckBox()
  2658. # ecut_item.set_value(data['extracut'])
  2659. # widget.setCellWidget(row, 20, ecut_item)
  2660. #
  2661. # ecut_length_item = FCDoubleSpinner()
  2662. # ecut_length_item.set_precision(self.decimals)
  2663. # ecut_length_item.set_range(0.0000, 9999.9999)
  2664. # ecut_length_item.set_value(data['extracut_length'])
  2665. # widget.setCellWidget(row, 21, ecut_length_item)
  2666. #
  2667. # toolchange_item = FCCheckBox()
  2668. # toolchange_item.set_value(data['toolchange'])
  2669. # widget.setCellWidget(row, 22, toolchange_item)
  2670. #
  2671. # toolchangexy_item = QtWidgets.QTableWidgetItem(str(data['toolchangexy']) if data['toolchangexy'] else '')
  2672. # widget.setItem(row, 23, toolchangexy_item)
  2673. #
  2674. # toolchangez_item = FCDoubleSpinner()
  2675. # toolchangez_item.set_precision(self.decimals)
  2676. # toolchangez_item.setSingleStep(0.1)
  2677. # if self.app.defaults['global_machinist_setting']:
  2678. # toolchangez_item.set_range(-9999.9999, 9999.9999)
  2679. # else:
  2680. # toolchangez_item.set_range(0.0000, 9999.9999)
  2681. #
  2682. # toolchangez_item.set_value(float(data['toolchangez']))
  2683. # widget.setCellWidget(row, 24, toolchangez_item)
  2684. #
  2685. # startz_item = QtWidgets.QTableWidgetItem(str(data['startz']) if data['startz'] else '')
  2686. # widget.setItem(row, 25, startz_item)
  2687. #
  2688. # endz_item = FCDoubleSpinner()
  2689. # endz_item.set_precision(self.decimals)
  2690. # endz_item.setSingleStep(0.1)
  2691. # if self.app.defaults['global_machinist_setting']:
  2692. # endz_item.set_range(-9999.9999, 9999.9999)
  2693. # else:
  2694. # endz_item.set_range(0.0000, 9999.9999)
  2695. #
  2696. # endz_item.set_value(float(data['endz']))
  2697. # widget.setCellWidget(row, 26, endz_item)
  2698. #
  2699. # def on_tool_add(self):
  2700. # """
  2701. # Add a tool in the DB Tool Table
  2702. # :return: None
  2703. # """
  2704. #
  2705. # default_data = {}
  2706. # default_data.update({
  2707. # "cutz": float(self.app.defaults["geometry_cutz"]),
  2708. # "multidepth": self.app.defaults["geometry_multidepth"],
  2709. # "depthperpass": float(self.app.defaults["geometry_depthperpass"]),
  2710. # "vtipdia": float(self.app.defaults["geometry_vtipdia"]),
  2711. # "vtipangle": float(self.app.defaults["geometry_vtipangle"]),
  2712. # "travelz": float(self.app.defaults["geometry_travelz"]),
  2713. # "feedrate": float(self.app.defaults["geometry_feedrate"]),
  2714. # "feedrate_z": float(self.app.defaults["geometry_feedrate_z"]),
  2715. # "feedrate_rapid": float(self.app.defaults["geometry_feedrate_rapid"]),
  2716. # "spindlespeed": self.app.defaults["geometry_spindlespeed"],
  2717. # "dwell": self.app.defaults["geometry_dwell"],
  2718. # "dwelltime": float(self.app.defaults["geometry_dwelltime"]),
  2719. # "ppname_g": self.app.defaults["geometry_ppname_g"],
  2720. # "extracut": self.app.defaults["geometry_extracut"],
  2721. # "extracut_length": float(self.app.defaults["geometry_extracut_length"]),
  2722. # "toolchange": self.app.defaults["geometry_toolchange"],
  2723. # "toolchangexy": self.app.defaults["geometry_toolchangexy"],
  2724. # "toolchangez": float(self.app.defaults["geometry_toolchangez"]),
  2725. # "startz": self.app.defaults["geometry_startz"],
  2726. # "endz": float(self.app.defaults["geometry_endz"])
  2727. # })
  2728. #
  2729. # dict_elem = {}
  2730. # dict_elem['name'] = 'new_tool'
  2731. # if type(self.app.defaults["geometry_cnctooldia"]) == float:
  2732. # dict_elem['tooldia'] = self.app.defaults["geometry_cnctooldia"]
  2733. # else:
  2734. # try:
  2735. # tools_string = self.app.defaults["geometry_cnctooldia"].split(",")
  2736. # tools_diameters = [eval(a) for a in tools_string if a != '']
  2737. # dict_elem['tooldia'] = tools_diameters[0] if tools_diameters else 0.0
  2738. # except Exception as e:
  2739. # self.app.log.debug("ToolDB.on_tool_add() --> %s" % str(e))
  2740. # return
  2741. #
  2742. # dict_elem['offset'] = 'Path'
  2743. # dict_elem['offset_value'] = 0.0
  2744. # dict_elem['type'] = 'Rough'
  2745. # dict_elem['tool_type'] = 'C1'
  2746. # dict_elem['data'] = default_data
  2747. #
  2748. # new_toolid = len(self.db_tool_dict) + 1
  2749. # self.db_tool_dict[new_toolid] = deepcopy(dict_elem)
  2750. #
  2751. # # add the new entry to the Tools DB table
  2752. # self.build_db_ui()
  2753. # self.callback_on_edited()
  2754. # self.app.inform.emit('[success] %s' % _("Tool added to DB."))
  2755. #
  2756. # def on_tool_copy(self):
  2757. # """
  2758. # Copy a selection of Tools in the Tools DB table
  2759. # :return:
  2760. # """
  2761. # new_tool_id = self.table_widget.rowCount() + 1
  2762. # for model_index in self.table_widget.selectionModel().selectedRows():
  2763. # # index = QtCore.QPersistentModelIndex(model_index)
  2764. # old_tool_id = self.table_widget.item(model_index.row(), 0).text()
  2765. # new_tool_id += 1
  2766. #
  2767. # for toolid, dict_val in list(self.db_tool_dict.items()):
  2768. # if int(old_tool_id) == int(toolid):
  2769. # self.db_tool_dict.update({
  2770. # new_tool_id: deepcopy(dict_val)
  2771. # })
  2772. #
  2773. # self.build_db_ui()
  2774. # self.callback_on_edited()
  2775. # self.app.inform.emit('[success] %s' % _("Tool copied from Tools DB."))
  2776. #
  2777. # def on_tool_delete(self):
  2778. # """
  2779. # Delete a selection of Tools in the Tools DB table
  2780. # :return:
  2781. # """
  2782. # for model_index in self.table_widget.selectionModel().selectedRows():
  2783. # # index = QtCore.QPersistentModelIndex(model_index)
  2784. # toolname_to_remove = self.table_widget.item(model_index.row(), 0).text()
  2785. #
  2786. # for toolid, dict_val in list(self.db_tool_dict.items()):
  2787. # if int(toolname_to_remove) == int(toolid):
  2788. # # remove from the storage
  2789. # self.db_tool_dict.pop(toolid, None)
  2790. #
  2791. # self.build_db_ui()
  2792. # self.callback_on_edited()
  2793. # self.app.inform.emit('[success] %s' % _("Tool removed from Tools DB."))
  2794. #
  2795. # def on_export_tools_db_file(self):
  2796. # self.app.defaults.report_usage("on_export_tools_db_file")
  2797. # self.app.log.debug("on_export_tools_db_file()")
  2798. #
  2799. # date = str(datetime.today()).rpartition('.')[0]
  2800. # date = ''.join(c for c in date if c not in ':-')
  2801. # date = date.replace(' ', '_')
  2802. #
  2803. # filter__ = "Text File (*.TXT);;All Files (*.*)"
  2804. # filename, _f = FCFileSaveDialog.get_saved_filename(caption=_("Export Tools Database"),
  2805. # directory='{l_save}/FlatCAM_{n}_{date}'.format(
  2806. # l_save=str(self.app.get_last_save_folder()),
  2807. # n=_("Tools_Database"),
  2808. # date=date),
  2809. # ext_filter=filter__)
  2810. #
  2811. # filename = str(filename)
  2812. #
  2813. # if filename == "":
  2814. # self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled."))
  2815. # return
  2816. # else:
  2817. # try:
  2818. # f = open(filename, 'w')
  2819. # f.close()
  2820. # except PermissionError:
  2821. # self.app.inform.emit('[WARNING] %s' %
  2822. # _("Permission denied, saving not possible.\n"
  2823. # "Most likely another app is holding the file open and not accessible."))
  2824. # return
  2825. # except IOError:
  2826. # self.app.log.debug('Creating a new Tools DB file ...')
  2827. # f = open(filename, 'w')
  2828. # f.close()
  2829. # except Exception:
  2830. # e = sys.exc_info()[0]
  2831. # self.app.log.error("Could not load Tools DB file.")
  2832. # self.app.log.error(str(e))
  2833. # self.app.inform.emit('[ERROR_NOTCL] %s' % _("Could not load Tools DB file."))
  2834. # return
  2835. #
  2836. # # Save update options
  2837. # try:
  2838. # # Save Tools DB in a file
  2839. # try:
  2840. # with open(filename, "w") as f:
  2841. # json.dump(self.db_tool_dict, f, default=to_dict, indent=2)
  2842. # except Exception as e:
  2843. # self.app.log.debug("App.on_save_tools_db() --> %s" % str(e))
  2844. # self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  2845. # return
  2846. # except Exception:
  2847. # self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  2848. # return
  2849. #
  2850. # self.app.inform.emit('[success] %s: %s' % (_("Exported Tools DB to"), filename))
  2851. #
  2852. # def on_import_tools_db_file(self):
  2853. # self.app.defaults.report_usage("on_import_tools_db_file")
  2854. # self.app.log.debug("on_import_tools_db_file()")
  2855. #
  2856. # filter__ = "Text File (*.TXT);;All Files (*.*)"
  2857. # filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Tools DB"), filter=filter__)
  2858. #
  2859. # if filename == "":
  2860. # self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled."))
  2861. # else:
  2862. # try:
  2863. # with open(filename) as f:
  2864. # tools_in_db = f.read()
  2865. # except IOError:
  2866. # self.app.log.error("Could not load Tools DB file.")
  2867. # self.app.inform.emit('[ERROR_NOTCL] %s' % _("Could not load Tools DB file."))
  2868. # return
  2869. #
  2870. # try:
  2871. # self.db_tool_dict = json.loads(tools_in_db)
  2872. # except Exception:
  2873. # e = sys.exc_info()[0]
  2874. # self.app.log.error(str(e))
  2875. # self.app.inform.emit('[ERROR] %s' % _("Failed to parse Tools DB file."))
  2876. # return
  2877. #
  2878. # self.app.inform.emit('[success] %s: %s' % (_("Loaded Tools DB from"), filename))
  2879. # self.build_db_ui()
  2880. # self.callback_on_edited()
  2881. #
  2882. # def on_save_tools_db(self, silent=False):
  2883. # self.app.log.debug("ToolsDB.on_save_button() --> Saving Tools Database to file.")
  2884. #
  2885. # filename = self.app.tools_database_path()
  2886. #
  2887. # # Preferences save, update the color of the Tools DB Tab text
  2888. # for idx in range(self.app_ui.plot_tab_area.count()):
  2889. # if self.app_ui.plot_tab_area.tabText(idx) == _("Tools Database"):
  2890. # self.app_ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('black'))
  2891. #
  2892. # # Save Tools DB in a file
  2893. # try:
  2894. # f = open(filename, "w")
  2895. # json.dump(self.db_tool_dict, f, default=to_dict, indent=2)
  2896. # f.close()
  2897. # except Exception as e:
  2898. # self.app.log.debug("ToolsDB.on_save_tools_db() --> %s" % str(e))
  2899. # self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write Tools DB to file."))
  2900. # return
  2901. #
  2902. # if not silent:
  2903. # self.app.inform.emit('[success] %s' % _("Saved Tools DB."))
  2904. #
  2905. # def ui_connect(self):
  2906. # try:
  2907. # try:
  2908. # self.table_widget.itemChanged.disconnect(self.callback_on_edited)
  2909. # except (TypeError, AttributeError):
  2910. # pass
  2911. # self.table_widget.itemChanged.connect(self.callback_on_edited)
  2912. # except AttributeError:
  2913. # pass
  2914. #
  2915. # for row in range(self.table_widget.rowCount()):
  2916. # for col in range(self.table_widget.columnCount()):
  2917. # # ComboBox
  2918. # try:
  2919. # try:
  2920. # self.table_widget.cellWidget(row, col).currentIndexChanged.disconnect(self.callback_on_edited)
  2921. # except (TypeError, AttributeError):
  2922. # pass
  2923. # self.table_widget.cellWidget(row, col).currentIndexChanged.connect(self.callback_on_edited)
  2924. # except AttributeError:
  2925. # pass
  2926. #
  2927. # # CheckBox
  2928. # try:
  2929. # try:
  2930. # self.table_widget.cellWidget(row, col).toggled.disconnect(self.callback_on_edited)
  2931. # except (TypeError, AttributeError):
  2932. # pass
  2933. # self.table_widget.cellWidget(row, col).toggled.connect(self.callback_on_edited)
  2934. # except AttributeError:
  2935. # pass
  2936. #
  2937. # # SpinBox, DoubleSpinBox
  2938. # try:
  2939. # try:
  2940. # self.table_widget.cellWidget(row, col).valueChanged.disconnect(self.callback_on_edited)
  2941. # except (TypeError, AttributeError):
  2942. # pass
  2943. # self.table_widget.cellWidget(row, col).valueChanged.connect(self.callback_on_edited)
  2944. # except AttributeError:
  2945. # pass
  2946. #
  2947. # def ui_disconnect(self):
  2948. # try:
  2949. # self.table_widget.itemChanged.disconnect(self.callback_on_edited)
  2950. # except (TypeError, AttributeError):
  2951. # pass
  2952. #
  2953. # for row in range(self.table_widget.rowCount()):
  2954. # for col in range(self.table_widget.columnCount()):
  2955. # # ComboBox
  2956. # try:
  2957. # self.table_widget.cellWidget(row, col).currentIndexChanged.disconnect(self.callback_on_edited)
  2958. # except (TypeError, AttributeError):
  2959. # pass
  2960. #
  2961. # # CheckBox
  2962. # try:
  2963. # self.table_widget.cellWidget(row, col).toggled.disconnect(self.callback_on_edited)
  2964. # except (TypeError, AttributeError):
  2965. # pass
  2966. #
  2967. # # SpinBox, DoubleSpinBox
  2968. # try:
  2969. # self.table_widget.cellWidget(row, col).valueChanged.disconnect(self.callback_on_edited)
  2970. # except (TypeError, AttributeError):
  2971. # pass
  2972. #
  2973. # def callback_on_edited(self):
  2974. #
  2975. # # update the dictionary storage self.db_tool_dict
  2976. # self.db_tool_dict.clear()
  2977. # dict_elem = {}
  2978. # default_data = {}
  2979. #
  2980. # for row in range(self.table_widget.rowCount()):
  2981. # new_toolid = row + 1
  2982. # for col in range(self.table_widget.columnCount()):
  2983. # column_header_text = self.table_widget.horizontalHeaderItem(col).text()
  2984. # if column_header_text == _('Tool Name'):
  2985. # dict_elem['name'] = self.table_widget.item(row, col).text()
  2986. # elif column_header_text == _('Tool Dia'):
  2987. # dict_elem['tooldia'] = self.table_widget.cellWidget(row, col).get_value()
  2988. # elif column_header_text == _('Tool Offset'):
  2989. # dict_elem['offset'] = self.table_widget.cellWidget(row, col).get_value()
  2990. # elif column_header_text == _('Custom Offset'):
  2991. # dict_elem['offset_value'] = self.table_widget.cellWidget(row, col).get_value()
  2992. # elif column_header_text == _('Tool Type'):
  2993. # dict_elem['type'] = self.table_widget.cellWidget(row, col).get_value()
  2994. # elif column_header_text == _('Tool Shape'):
  2995. # dict_elem['tool_type'] = self.table_widget.cellWidget(row, col).get_value()
  2996. # else:
  2997. # if column_header_text == _('Cut Z'):
  2998. # default_data['cutz'] = self.table_widget.cellWidget(row, col).get_value()
  2999. # elif column_header_text == _('MultiDepth'):
  3000. # default_data['multidepth'] = self.table_widget.cellWidget(row, col).get_value()
  3001. # elif column_header_text == _('DPP'):
  3002. # default_data['depthperpass'] = self.table_widget.cellWidget(row, col).get_value()
  3003. # elif column_header_text == _('V-Dia'):
  3004. # default_data['vtipdia'] = self.table_widget.cellWidget(row, col).get_value()
  3005. # elif column_header_text == _('V-Angle'):
  3006. # default_data['vtipangle'] = self.table_widget.cellWidget(row, col).get_value()
  3007. # elif column_header_text == _('Travel Z'):
  3008. # default_data['travelz'] = self.table_widget.cellWidget(row, col).get_value()
  3009. # elif column_header_text == _('FR'):
  3010. # default_data['feedrate'] = self.table_widget.cellWidget(row, col).get_value()
  3011. # elif column_header_text == _('FR Z'):
  3012. # default_data['feedrate_z'] = self.table_widget.cellWidget(row, col).get_value()
  3013. # elif column_header_text == _('FR Rapids'):
  3014. # default_data['feedrate_rapid'] = self.table_widget.cellWidget(row, col).get_value()
  3015. # elif column_header_text == _('Spindle Speed'):
  3016. # default_data['spindlespeed'] = self.table_widget.cellWidget(row, col).get_value()
  3017. # elif column_header_text == _('Dwell'):
  3018. # default_data['dwell'] = self.table_widget.cellWidget(row, col).get_value()
  3019. # elif column_header_text == _('Dwelltime'):
  3020. # default_data['dwelltime'] = self.table_widget.cellWidget(row, col).get_value()
  3021. # elif column_header_text == _('Preprocessor'):
  3022. # default_data['ppname_g'] = self.table_widget.cellWidget(row, col).get_value()
  3023. # elif column_header_text == _('ExtraCut'):
  3024. # default_data['extracut'] = self.table_widget.cellWidget(row, col).get_value()
  3025. # elif column_header_text == _("E-Cut Length"):
  3026. # default_data['extracut_length'] = self.table_widget.cellWidget(row, col).get_value()
  3027. # elif column_header_text == _('Toolchange'):
  3028. # default_data['toolchange'] = self.table_widget.cellWidget(row, col).get_value()
  3029. # elif column_header_text == _('Toolchange XY'):
  3030. # default_data['toolchangexy'] = self.table_widget.item(row, col).text()
  3031. # elif column_header_text == _('Toolchange Z'):
  3032. # default_data['toolchangez'] = self.table_widget.cellWidget(row, col).get_value()
  3033. # elif column_header_text == _('Start Z'):
  3034. # default_data['startz'] = float(self.table_widget.item(row, col).text()) \
  3035. # if self.table_widget.item(row, col).text() != '' else None
  3036. # elif column_header_text == _('End Z'):
  3037. # default_data['endz'] = self.table_widget.cellWidget(row, col).get_value()
  3038. #
  3039. # dict_elem['data'] = default_data
  3040. # self.db_tool_dict.update(
  3041. # {
  3042. # new_toolid: deepcopy(dict_elem)
  3043. # }
  3044. # )
  3045. #
  3046. # self.callback_app()
  3047. #
  3048. # def on_tool_requested_from_app(self):
  3049. # if not self.table_widget.selectionModel().selectedRows():
  3050. # self.app.inform.emit('[WARNING_NOTCL] %s...' % _("No Tool/row selected in the Tools Database table"))
  3051. # return
  3052. #
  3053. # model_index_list = self.table_widget.selectionModel().selectedRows()
  3054. # for model_index in model_index_list:
  3055. # selected_row = model_index.row()
  3056. # tool_uid = selected_row + 1
  3057. # for key in self.db_tool_dict.keys():
  3058. # if str(key) == str(tool_uid):
  3059. # selected_tool = self.db_tool_dict[key]
  3060. # self.on_tool_request(tool=selected_tool)
  3061. #
  3062. # def on_cancel_tool(self):
  3063. # for idx in range(self.app_ui.plot_tab_area.count()):
  3064. # if self.app_ui.plot_tab_area.tabText(idx) == _("Tools Database"):
  3065. # wdg = self.app_ui.plot_tab_area.widget(idx)
  3066. # wdg.deleteLater()
  3067. # self.app_ui.plot_tab_area.removeTab(idx)
  3068. # self.app.inform.emit('%s' % _("Cancelled adding tool from DB."))
  3069. #
  3070. # # def resize_new_tool_table_widget(self, min_size, max_size):
  3071. # # """
  3072. # # Resize the table widget responsible for adding new tool in the Tool Database
  3073. # #
  3074. # # :param min_size: passed by rangeChanged signal or the self.new_tool_table_widget.horizontalScrollBar()
  3075. # # :param max_size: passed by rangeChanged signal or the self.new_tool_table_widget.horizontalScrollBar()
  3076. # # :return:
  3077. # # """
  3078. # # t_height = self.t_height
  3079. # # if max_size > min_size:
  3080. # # t_height = self.t_height + self.new_tool_table_widget.verticalScrollBar().height()
  3081. # #
  3082. # # self.new_tool_table_widget.setMaximumHeight(t_height)
  3083. #
  3084. # def closeEvent(self, QCloseEvent):
  3085. # super().closeEvent(QCloseEvent)