appDatabase.py 149 KB

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