appDatabase.py 153 KB

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