appDatabase.py 155 KB

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