appDatabase.py 151 KB

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