appDatabase.py 151 KB

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