ObjectUI.py 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. import sys
  2. from PyQt5 import QtGui, QtCore, QtWidgets, QtWidgets
  3. from GUIElements import FCEntry, FloatEntry, EvalEntry, FCCheckBox, FCTable, \
  4. LengthEntry, FCTextArea, IntEntry, RadioSet, OptionalInputSection, FCComboBox, FloatEntry2, EvalEntry2
  5. from camlib import Excellon
  6. class ObjectUI(QtWidgets.QWidget):
  7. """
  8. Base class for the UI of FlatCAM objects. Deriving classes should
  9. put UI elements in ObjectUI.custom_box (QtWidgets.QLayout).
  10. """
  11. def __init__(self, icon_file='share/flatcam_icon32.png', title='FlatCAM Object', parent=None):
  12. QtWidgets.QWidget.__init__(self, parent=parent)
  13. layout = QtWidgets.QVBoxLayout()
  14. self.setLayout(layout)
  15. ## Page Title box (spacing between children)
  16. self.title_box = QtWidgets.QHBoxLayout()
  17. layout.addLayout(self.title_box)
  18. ## Page Title icon
  19. pixmap = QtGui.QPixmap(icon_file)
  20. self.icon = QtWidgets.QLabel()
  21. self.icon.setPixmap(pixmap)
  22. self.title_box.addWidget(self.icon, stretch=0)
  23. ## Title label
  24. self.title_label = QtWidgets.QLabel("<font size=5><b>" + title + "</b></font>")
  25. self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  26. self.title_box.addWidget(self.title_label, stretch=1)
  27. ## App Level label
  28. self.level = QtWidgets.QLabel("")
  29. self.level.setToolTip(
  30. "BASIC is suitable for a beginner. Many parameters\n"
  31. "are hidden from the user in this mode.\n"
  32. "ADVANCED mode will make available all parameters.\n\n"
  33. "To change the application LEVEL, go to:\n"
  34. "Edit -> Preferences -> General and check:\n"
  35. "'APP. LEVEL' radio button."
  36. )
  37. self.level.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  38. self.title_box.addWidget(self.level)
  39. ## Box box for custom widgets
  40. # This gets populated in offspring implementations.
  41. self.custom_box = QtWidgets.QVBoxLayout()
  42. layout.addLayout(self.custom_box)
  43. ###########################
  44. ## Common to all objects ##
  45. ###########################
  46. #### Scale ####
  47. self.scale_label = QtWidgets.QLabel('<b>Scale:</b>')
  48. self.scale_label.setToolTip(
  49. "Change the size of the object."
  50. )
  51. layout.addWidget(self.scale_label)
  52. self.scale_grid = QtWidgets.QGridLayout()
  53. layout.addLayout(self.scale_grid)
  54. # Factor
  55. faclabel = QtWidgets.QLabel('Factor:')
  56. faclabel.setToolTip(
  57. "Factor by which to multiply\n"
  58. "geometric features of this object."
  59. )
  60. self.scale_grid.addWidget(faclabel, 0, 0)
  61. self.scale_entry = FloatEntry2()
  62. self.scale_entry.set_value(1.0)
  63. self.scale_grid.addWidget(self.scale_entry, 0, 1)
  64. # GO Button
  65. self.scale_button = QtWidgets.QPushButton('Scale')
  66. self.scale_button.setToolTip(
  67. "Perform scaling operation."
  68. )
  69. self.scale_button.setFixedWidth(40)
  70. self.scale_grid.addWidget(self.scale_button, 0, 2)
  71. #### Offset ####
  72. self.offset_label = QtWidgets.QLabel('<b>Offset:</b>')
  73. self.offset_label.setToolTip(
  74. "Change the position of this object."
  75. )
  76. layout.addWidget(self.offset_label)
  77. self.offset_grid = QtWidgets.QGridLayout()
  78. layout.addLayout(self.offset_grid)
  79. self.offset_vectorlabel = QtWidgets.QLabel('Vector:')
  80. self.offset_vectorlabel.setToolTip(
  81. "Amount by which to move the object\n"
  82. "in the x and y axes in (x, y) format."
  83. )
  84. self.offset_grid.addWidget(self.offset_vectorlabel, 0, 0)
  85. self.offsetvector_entry = EvalEntry2()
  86. self.offsetvector_entry.setText("(0.0, 0.0)")
  87. self.offset_grid.addWidget(self.offsetvector_entry, 0, 1)
  88. self.offset_button = QtWidgets.QPushButton('Offset')
  89. self.offset_button.setToolTip(
  90. "Perform the offset operation."
  91. )
  92. self.offset_button.setFixedWidth(40)
  93. self.offset_grid.addWidget(self.offset_button, 0, 2)
  94. layout.addStretch()
  95. class GerberObjectUI(ObjectUI):
  96. """
  97. User interface for Gerber objects.
  98. """
  99. def __init__(self, parent=None):
  100. ObjectUI.__init__(self, title='Gerber Object', parent=parent)
  101. # Plot options
  102. grid0 = QtWidgets.QGridLayout()
  103. grid0.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  104. self.custom_box.addLayout(grid0)
  105. self.plot_options_label = QtWidgets.QLabel("<b>Plot Options:</b>")
  106. grid0.addWidget(self.plot_options_label, 0, 0)
  107. # Solid CB
  108. self.solid_cb = FCCheckBox(label='Solid ')
  109. self.solid_cb.setToolTip(
  110. "Solid color polygons."
  111. )
  112. self.solid_cb.setFixedWidth(50)
  113. grid0.addWidget(self.solid_cb, 0, 1)
  114. # Multicolored CB
  115. self.multicolored_cb = FCCheckBox(label='M-Color ')
  116. self.multicolored_cb.setToolTip(
  117. "Draw polygons in different colors."
  118. )
  119. self.multicolored_cb.setFixedWidth(55)
  120. grid0.addWidget(self.multicolored_cb, 0, 2)
  121. ## Object name
  122. self.name_hlay = QtWidgets.QHBoxLayout()
  123. self.custom_box.addLayout(self.name_hlay)
  124. name_label = QtWidgets.QLabel("<b>Name:</b>")
  125. self.name_entry = FCEntry()
  126. self.name_entry.setFocusPolicy(QtCore.Qt.StrongFocus)
  127. self.name_hlay.addWidget(name_label)
  128. self.name_hlay.addWidget(self.name_entry)
  129. hlay_plot = QtWidgets.QHBoxLayout()
  130. self.custom_box.addLayout(hlay_plot)
  131. #### Gerber Apertures ####
  132. self.apertures_table_label = QtWidgets.QLabel('<b>Apertures Table</b>')
  133. self.apertures_table_label.setToolTip(
  134. "Apertures in this Gerber object."
  135. )
  136. hlay_plot.addWidget(self.apertures_table_label)
  137. # Aperture Table Visibility CB
  138. self.aperture_table_visibility_cb = FCCheckBox()
  139. hlay_plot.addWidget(self.aperture_table_visibility_cb)
  140. # Plot CB
  141. self.plot_cb = FCCheckBox('Plot Object')
  142. self.plot_cb.setToolTip(
  143. "Plot (show) this object."
  144. )
  145. self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
  146. hlay_plot.addStretch()
  147. hlay_plot.addWidget(self.plot_cb)
  148. self.apertures_table = FCTable()
  149. self.custom_box.addWidget(self.apertures_table)
  150. self.apertures_table.setColumnCount(6)
  151. self.apertures_table.setHorizontalHeaderLabels(['#', 'Code', 'Type', 'Size', 'Dim', 'P'])
  152. self.apertures_table.setSortingEnabled(False)
  153. self.apertures_table.horizontalHeaderItem(0).setToolTip(
  154. "Index")
  155. self.apertures_table.horizontalHeaderItem(1).setToolTip(
  156. "Aperture Code")
  157. self.apertures_table.horizontalHeaderItem(2).setToolTip(
  158. "Type of aperture: circular, rectangle, macros etc")
  159. self.apertures_table.horizontalHeaderItem(4).setToolTip(
  160. "Aperture Size:")
  161. self.apertures_table.horizontalHeaderItem(4).setToolTip(
  162. "Aperture Dimensions:\n"
  163. " - (width, height) for R, O type.\n"
  164. " - (dia, nVertices) for P type")
  165. self.apertures_table.horizontalHeaderItem(5).setToolTip(
  166. "Toggle display of the aperture instances.")
  167. # start with apertures table hidden
  168. self.apertures_table.setVisible(False)
  169. # hide the plot column. for now I can't plot individually the apertures without making the plot really ugly
  170. self.apertures_table.setColumnHidden(5, True)
  171. #
  172. # self.empty_label = QtWidgets.QLabel('')
  173. # self.custom_box.addWidget(self.empty_label)
  174. # Isolation Routing
  175. self.isolation_routing_label = QtWidgets.QLabel("<b>Isolation Routing:</b>")
  176. self.isolation_routing_label.setToolTip(
  177. "Create a Geometry object with\n"
  178. "toolpaths to cut outside polygons."
  179. )
  180. self.custom_box.addWidget(self.isolation_routing_label)
  181. grid1 = QtWidgets.QGridLayout()
  182. self.custom_box.addLayout(grid1)
  183. tdlabel = QtWidgets.QLabel('Tool dia:')
  184. tdlabel.setToolTip(
  185. "Diameter of the cutting tool.\n"
  186. "If you want to have an isolation path\n"
  187. "inside the actual shape of the Gerber\n"
  188. "feature, use a negative value for\n"
  189. "this parameter."
  190. )
  191. grid1.addWidget(tdlabel, 0, 0)
  192. self.iso_tool_dia_entry = LengthEntry()
  193. grid1.addWidget(self.iso_tool_dia_entry, 0, 1)
  194. passlabel = QtWidgets.QLabel('Passes:')
  195. passlabel.setToolTip(
  196. "Width of the isolation gap in\n"
  197. "number (integer) of tool widths."
  198. )
  199. grid1.addWidget(passlabel, 1, 0)
  200. self.iso_width_entry = IntEntry()
  201. grid1.addWidget(self.iso_width_entry, 1, 1)
  202. overlabel = QtWidgets.QLabel('Pass overlap:')
  203. overlabel.setToolTip(
  204. "How much (fraction) of the tool width to overlap each tool pass.\n"
  205. "Example:\n"
  206. "A value here of 0.25 means an overlap of 25% from the tool diameter found above."
  207. )
  208. grid1.addWidget(overlabel, 2, 0)
  209. self.iso_overlap_entry = FloatEntry()
  210. grid1.addWidget(self.iso_overlap_entry, 2, 1)
  211. # Milling Type Radio Button
  212. self.milling_type_label = QtWidgets.QLabel('Milling Type:')
  213. self.milling_type_label.setToolTip(
  214. "Milling type:\n"
  215. "- climb / best for precision milling and to reduce tool usage\n"
  216. "- conventional / useful when there is no backlash compensation"
  217. )
  218. grid1.addWidget(self.milling_type_label, 3, 0)
  219. self.milling_type_radio = RadioSet([{'label': 'Climb', 'value': 'cl'},
  220. {'label': 'Conv.', 'value': 'cv'}])
  221. grid1.addWidget(self.milling_type_radio, 3, 1)
  222. # combine all passes CB
  223. self.combine_passes_cb = FCCheckBox(label='Combine')
  224. self.combine_passes_cb.setToolTip(
  225. "Combine all passes into one object"
  226. )
  227. grid1.addWidget(self.combine_passes_cb, 4, 0)
  228. # generate follow
  229. self.follow_cb = FCCheckBox(label='"Follow"')
  230. self.follow_cb.setToolTip(
  231. "Generate a 'Follow' geometry.\n"
  232. "This means that it will cut through\n"
  233. "the middle of the trace."
  234. )
  235. grid1.addWidget(self.follow_cb, 4, 1)
  236. self.gen_iso_label = QtWidgets.QLabel("<b>Generate Isolation Geometry:</b>")
  237. self.gen_iso_label.setToolTip(
  238. "Create a Geometry object with toolpaths to cut \n"
  239. "isolation outside, inside or on both sides of the\n"
  240. "object. For a Gerber object outside means outside\n"
  241. "of the Gerber feature and inside means inside of\n"
  242. "the Gerber feature, if possible at all. This means\n"
  243. "that only if the Gerber feature has openings inside, they\n"
  244. "will be isolated. If what is wanted is to cut isolation\n"
  245. "inside the actual Gerber feature, use a negative tool\n"
  246. "diameter above."
  247. )
  248. self.custom_box.addWidget(self.gen_iso_label)
  249. hlay_1 = QtWidgets.QHBoxLayout()
  250. self.custom_box.addLayout(hlay_1)
  251. hlay_1.addStretch()
  252. self.generate_ext_iso_button = QtWidgets.QPushButton('Ext Geo')
  253. self.generate_ext_iso_button.setToolTip(
  254. "Create the Geometry Object\n"
  255. "for isolation routing containing\n"
  256. "only the exteriors geometry."
  257. )
  258. self.generate_ext_iso_button.setFixedWidth(60)
  259. hlay_1.addWidget(self.generate_ext_iso_button)
  260. self.generate_int_iso_button = QtWidgets.QPushButton('Int Geo')
  261. self.generate_int_iso_button.setToolTip(
  262. "Create the Geometry Object\n"
  263. "for isolation routing containing\n"
  264. "only the interiors geometry."
  265. )
  266. self.generate_int_iso_button.setFixedWidth(60)
  267. hlay_1.addWidget(self.generate_int_iso_button)
  268. self.generate_iso_button = QtWidgets.QPushButton('FULL Geo')
  269. self.generate_iso_button.setToolTip(
  270. "Create the Geometry Object\n"
  271. "for isolation routing. It contains both\n"
  272. "the interiors and exteriors geometry."
  273. )
  274. self.generate_iso_button.setFixedWidth(80)
  275. hlay_1.addWidget(self.generate_iso_button)
  276. # when the follow checkbox is checked then the exteriors and interiors isolation generation buttons
  277. # are disabled as is doesn't make sense to have them enabled due of the nature of "follow"
  278. self.ois_iso = OptionalInputSection(self.follow_cb,
  279. [self.generate_int_iso_button, self.generate_ext_iso_button], logic=False)
  280. grid2 = QtWidgets.QGridLayout()
  281. self.custom_box.addLayout(grid2)
  282. ## Clear non-copper regions
  283. self.clearcopper_label = QtWidgets.QLabel("<b>Clear non-copper:</b>")
  284. self.clearcopper_label.setToolTip(
  285. "Create a Geometry object with\n"
  286. "toolpaths to cut all non-copper regions."
  287. )
  288. grid2.addWidget(self.clearcopper_label, 0, 0)
  289. self.generate_ncc_button = QtWidgets.QPushButton('NCC Tool')
  290. self.generate_ncc_button.setToolTip(
  291. "Create the Geometry Object\n"
  292. "for non-copper routing."
  293. )
  294. grid2.addWidget(self.generate_ncc_button, 0, 1)
  295. ## Board cutout
  296. self.board_cutout_label = QtWidgets.QLabel("<b>Board cutout:</b>")
  297. self.board_cutout_label.setToolTip(
  298. "Create toolpaths to cut around\n"
  299. "the PCB and separate it from\n"
  300. "the original board."
  301. )
  302. grid2.addWidget(self.board_cutout_label, 1, 0)
  303. self.generate_cutout_button = QtWidgets.QPushButton('Cutout Tool')
  304. self.generate_cutout_button.setToolTip(
  305. "Generate the geometry for\n"
  306. "the board cutout."
  307. )
  308. grid2.addWidget(self.generate_cutout_button, 1, 1)
  309. ## Non-copper regions
  310. self.noncopper_label = QtWidgets.QLabel("<b>Non-copper regions:</b>")
  311. self.noncopper_label.setToolTip(
  312. "Create polygons covering the\n"
  313. "areas without copper on the PCB.\n"
  314. "Equivalent to the inverse of this\n"
  315. "object. Can be used to remove all\n"
  316. "copper from a specified region."
  317. )
  318. self.custom_box.addWidget(self.noncopper_label)
  319. grid4 = QtWidgets.QGridLayout()
  320. self.custom_box.addLayout(grid4)
  321. # Margin
  322. bmlabel = QtWidgets.QLabel('Boundary Margin:')
  323. bmlabel.setToolTip(
  324. "Specify the edge of the PCB\n"
  325. "by drawing a box around all\n"
  326. "objects with this minimum\n"
  327. "distance."
  328. )
  329. grid4.addWidget(bmlabel, 0, 0)
  330. self.noncopper_margin_entry = LengthEntry()
  331. grid4.addWidget(self.noncopper_margin_entry, 0, 1)
  332. # Rounded corners
  333. self.noncopper_rounded_cb = FCCheckBox(label="Rounded corners")
  334. self.noncopper_rounded_cb.setToolTip(
  335. "Resulting geometry will have rounded corners."
  336. )
  337. grid4.addWidget(self.noncopper_rounded_cb, 1, 0)
  338. self.generate_noncopper_button = QtWidgets.QPushButton('Generate Geo')
  339. grid4.addWidget(self.generate_noncopper_button, 1, 1)
  340. ## Bounding box
  341. self.boundingbox_label = QtWidgets.QLabel('<b>Bounding Box:</b>')
  342. self.boundingbox_label.setToolTip(
  343. "Create a geometry surrounding the Gerber object.\n"
  344. "Square shape."
  345. )
  346. self.custom_box.addWidget(self.boundingbox_label)
  347. grid5 = QtWidgets.QGridLayout()
  348. self.custom_box.addLayout(grid5)
  349. bbmargin = QtWidgets.QLabel('Boundary Margin:')
  350. bbmargin.setToolTip(
  351. "Distance of the edges of the box\n"
  352. "to the nearest polygon."
  353. )
  354. grid5.addWidget(bbmargin, 0, 0)
  355. self.bbmargin_entry = LengthEntry()
  356. grid5.addWidget(self.bbmargin_entry, 0, 1)
  357. self.bbrounded_cb = FCCheckBox(label="Rounded corners")
  358. self.bbrounded_cb.setToolTip(
  359. "If the bounding box is \n"
  360. "to have rounded corners\n"
  361. "their radius is equal to\n"
  362. "the margin."
  363. )
  364. grid5.addWidget(self.bbrounded_cb, 1, 0)
  365. self.generate_bb_button = QtWidgets.QPushButton('Generate Geo')
  366. self.generate_bb_button.setToolTip(
  367. "Generate the Geometry object."
  368. )
  369. grid5.addWidget(self.generate_bb_button, 1, 1)
  370. class ExcellonObjectUI(ObjectUI):
  371. """
  372. User interface for Excellon objects.
  373. """
  374. def __init__(self, parent=None):
  375. ObjectUI.__init__(self, title='Excellon Object',
  376. icon_file='share/drill32.png',
  377. parent=parent)
  378. #### Plot options ####
  379. hlay_plot = QtWidgets.QHBoxLayout()
  380. self.custom_box.addLayout(hlay_plot)
  381. self.plot_options_label = QtWidgets.QLabel("<b>Plot Options:</b>")
  382. self.solid_cb = FCCheckBox(label='Solid')
  383. self.solid_cb.setToolTip(
  384. "Solid circles."
  385. )
  386. hlay_plot.addWidget(self.plot_options_label)
  387. hlay_plot.addStretch()
  388. hlay_plot.addWidget(self.solid_cb)
  389. ## Object name
  390. self.name_hlay = QtWidgets.QHBoxLayout()
  391. self.custom_box.addLayout(self.name_hlay)
  392. name_label = QtWidgets.QLabel("<b>Name:</b>")
  393. self.name_entry = FCEntry()
  394. self.name_entry.setFocusPolicy(QtCore.Qt.StrongFocus)
  395. self.name_hlay.addWidget(name_label)
  396. self.name_hlay.addWidget(self.name_entry)
  397. # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
  398. # this way I can hide/show the frame
  399. self.drills_frame = QtWidgets.QFrame()
  400. self.drills_frame.setContentsMargins(0, 0, 0, 0)
  401. self.custom_box.addWidget(self.drills_frame)
  402. self.tools_box = QtWidgets.QVBoxLayout()
  403. self.tools_box.setContentsMargins(0, 0, 0, 0)
  404. self.drills_frame.setLayout(self.tools_box)
  405. hlay_plot = QtWidgets.QHBoxLayout()
  406. self.tools_box.addLayout(hlay_plot)
  407. #### Tools Drills ####
  408. self.tools_table_label = QtWidgets.QLabel('<b>Tools Table</b>')
  409. self.tools_table_label.setToolTip(
  410. "Tools in this Excellon object\n"
  411. "when are used for drilling."
  412. )
  413. hlay_plot.addWidget(self.tools_table_label)
  414. # Plot CB
  415. self.plot_cb = FCCheckBox('Plot Object')
  416. self.plot_cb.setToolTip(
  417. "Plot (show) this object."
  418. )
  419. self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
  420. hlay_plot.addStretch()
  421. hlay_plot.addWidget(self.plot_cb)
  422. self.tools_table = FCTable()
  423. self.tools_box.addWidget(self.tools_table)
  424. self.tools_table.setColumnCount(6)
  425. self.tools_table.setHorizontalHeaderLabels(['#', 'Diameter', 'Drills', 'Slots', 'Offset Z', 'P'])
  426. self.tools_table.setSortingEnabled(False)
  427. self.tools_table.horizontalHeaderItem(0).setToolTip(
  428. "This is the Tool Number.\n"
  429. "When ToolChange is checked, on toolchange event this value\n"
  430. "will be showed as a T1, T2 ... Tn in the Machine Code.")
  431. self.tools_table.horizontalHeaderItem(1).setToolTip(
  432. "Tool Diameter. It's value (in current FlatCAM units) \n"
  433. "is the cut width into the material.")
  434. self.tools_table.horizontalHeaderItem(2).setToolTip(
  435. "The number of Drill holes. Holes that are drilled with\n"
  436. "a drill bit.")
  437. self.tools_table.horizontalHeaderItem(3).setToolTip(
  438. "The number of Slot holes. Holes that are created by\n"
  439. "milling them with an endmill bit.")
  440. self.tools_table.horizontalHeaderItem(4).setToolTip(
  441. "Some drill bits (the larger ones) need to drill deeper\n"
  442. "to create the desired exit hole diameter due of the tip shape.\n"
  443. "The value here can compensate the Cut Z parameter.")
  444. self.tools_table.horizontalHeaderItem(5).setToolTip(
  445. "Toggle display of the drills for the current tool.")
  446. self.empty_label = QtWidgets.QLabel('')
  447. self.tools_box.addWidget(self.empty_label)
  448. #### Create CNC Job ####
  449. self.cncjob_label = QtWidgets.QLabel('<b>Create CNC Job</b>')
  450. self.cncjob_label.setToolTip(
  451. "Create a CNC Job object\n"
  452. "for this drill object."
  453. )
  454. self.tools_box.addWidget(self.cncjob_label)
  455. grid1 = QtWidgets.QGridLayout()
  456. self.tools_box.addLayout(grid1)
  457. # Cut Z
  458. cutzlabel = QtWidgets.QLabel('Cut Z:')
  459. cutzlabel.setToolTip(
  460. "Drill depth (negative)\n"
  461. "below the copper surface."
  462. )
  463. grid1.addWidget(cutzlabel, 0, 0)
  464. self.cutz_entry = LengthEntry()
  465. grid1.addWidget(self.cutz_entry, 0, 1)
  466. # Travel Z (z_move)
  467. travelzlabel = QtWidgets.QLabel('Travel Z:')
  468. travelzlabel.setToolTip(
  469. "Tool height when travelling\n"
  470. "across the XY plane."
  471. )
  472. grid1.addWidget(travelzlabel, 1, 0)
  473. self.travelz_entry = LengthEntry()
  474. grid1.addWidget(self.travelz_entry, 1, 1)
  475. # Tool change:
  476. self.toolchange_cb = FCCheckBox("Tool change")
  477. self.toolchange_cb.setToolTip(
  478. "Include tool-change sequence\n"
  479. "in G-Code (Pause for tool change)."
  480. )
  481. grid1.addWidget(self.toolchange_cb, 2, 0)
  482. # Tool change Z:
  483. toolchzlabel = QtWidgets.QLabel("Tool change Z:")
  484. toolchzlabel.setToolTip(
  485. "Z-axis position (height) for\n"
  486. "tool change."
  487. )
  488. grid1.addWidget(toolchzlabel, 3, 0)
  489. self.toolchangez_entry = LengthEntry()
  490. grid1.addWidget(self.toolchangez_entry, 3, 1)
  491. self.ois_tcz_e = OptionalInputSection(self.toolchange_cb, [self.toolchangez_entry])
  492. # Start move Z:
  493. self.estartz_label = QtWidgets.QLabel("Start move Z:")
  494. self.estartz_label.setToolTip(
  495. "Tool height just before starting the work.\n"
  496. "Delete the value if you don't need this feature."
  497. )
  498. grid1.addWidget(self.estartz_label, 4, 0)
  499. self.estartz_entry = FloatEntry()
  500. grid1.addWidget(self.estartz_entry, 4, 1)
  501. # End move Z:
  502. self.eendz_label = QtWidgets.QLabel("End move Z:")
  503. self.eendz_label.setToolTip(
  504. "Z-axis position (height) for\n"
  505. "the last move."
  506. )
  507. grid1.addWidget(self.eendz_label, 5, 0)
  508. self.eendz_entry = LengthEntry()
  509. grid1.addWidget(self.eendz_entry, 5, 1)
  510. # Excellon Feedrate
  511. frlabel = QtWidgets.QLabel('Feedrate (Plunge):')
  512. frlabel.setToolTip(
  513. "Tool speed while drilling\n"
  514. "(in units per minute).\n"
  515. "This is for linear move G01."
  516. )
  517. grid1.addWidget(frlabel, 6, 0)
  518. self.feedrate_entry = LengthEntry()
  519. grid1.addWidget(self.feedrate_entry, 6, 1)
  520. # Excellon Rapid Feedrate
  521. self.feedrate_rapid_label = QtWidgets.QLabel('Feedrate Rapids:')
  522. self.feedrate_rapid_label.setToolTip(
  523. "Tool speed while drilling\n"
  524. "(in units per minute).\n"
  525. "This is for the rapid move G00."
  526. )
  527. grid1.addWidget(self.feedrate_rapid_label, 7, 0)
  528. self.feedrate_rapid_entry = LengthEntry()
  529. grid1.addWidget(self.feedrate_rapid_entry, 7, 1)
  530. # Spindlespeed
  531. spdlabel = QtWidgets.QLabel('Spindle speed:')
  532. spdlabel.setToolTip(
  533. "Speed of the spindle\n"
  534. "in RPM (optional)"
  535. )
  536. grid1.addWidget(spdlabel, 8, 0)
  537. self.spindlespeed_entry = IntEntry(allow_empty=True)
  538. grid1.addWidget(self.spindlespeed_entry, 8, 1)
  539. # Dwell
  540. self.dwell_cb = FCCheckBox('Dwell:')
  541. self.dwell_cb.setToolTip(
  542. "Pause to allow the spindle to reach its\n"
  543. "speed before cutting."
  544. )
  545. self.dwelltime_entry = FCEntry()
  546. self.dwelltime_entry.setToolTip(
  547. "Number of milliseconds for spindle to dwell."
  548. )
  549. grid1.addWidget(self.dwell_cb, 9, 0)
  550. grid1.addWidget(self.dwelltime_entry, 9, 1)
  551. self.ois_dwell = OptionalInputSection(self.dwell_cb, [self.dwelltime_entry])
  552. # postprocessor selection
  553. pp_excellon_label = QtWidgets.QLabel("Postprocessor:")
  554. pp_excellon_label.setToolTip(
  555. "The json file that dictates\n"
  556. "gcode output."
  557. )
  558. self.pp_excellon_name_cb = FCComboBox()
  559. self.pp_excellon_name_cb.setFocusPolicy(QtCore.Qt.StrongFocus)
  560. grid1.addWidget(pp_excellon_label, 10, 0)
  561. grid1.addWidget(self.pp_excellon_name_cb, 10, 1)
  562. # Probe depth
  563. self.pdepth_label = QtWidgets.QLabel("Probe Z depth:")
  564. self.pdepth_label.setToolTip(
  565. "The maximum depth that the probe is allowed\n"
  566. "to probe. Negative value, in current units."
  567. )
  568. grid1.addWidget(self.pdepth_label, 11, 0)
  569. self.pdepth_entry = FCEntry()
  570. grid1.addWidget(self.pdepth_entry, 11, 1)
  571. self.pdepth_label.hide()
  572. self.pdepth_entry.setVisible(False)
  573. # Probe feedrate
  574. self.feedrate_probe_label = QtWidgets.QLabel("Feedrate Probe:")
  575. self.feedrate_probe_label.setToolTip(
  576. "The feedrate used while the probe is probing."
  577. )
  578. grid1.addWidget(self.feedrate_probe_label, 12, 0)
  579. self.feedrate_probe_entry = FCEntry()
  580. grid1.addWidget(self.feedrate_probe_entry, 12, 1)
  581. self.feedrate_probe_label.hide()
  582. self.feedrate_probe_entry.setVisible(False)
  583. choose_tools_label = QtWidgets.QLabel(
  584. "Select from the Tools Table above\n"
  585. "the tools you want to include."
  586. )
  587. self.tools_box.addWidget(choose_tools_label)
  588. #### Choose what to use for Gcode creation: Drills, Slots or Both
  589. gcode_box = QtWidgets.QFormLayout()
  590. gcode_type_label = QtWidgets.QLabel('<b>Type: </b>')
  591. gcode_type_label.setToolTip(
  592. "Choose what to use for GCode generation:\n"
  593. "'Drills', 'Slots' or 'Both'.\n"
  594. "When choosing 'Slots' or 'Both', slots will be\n"
  595. "converted to a series of drills."
  596. )
  597. self.excellon_gcode_type_radio = RadioSet([{'label': 'Drills', 'value': 'drills'},
  598. {'label': 'Slots', 'value': 'slots'},
  599. {'label': 'Both', 'value': 'both'}])
  600. gcode_box.addRow(gcode_type_label, self.excellon_gcode_type_radio)
  601. self.tools_box.addLayout(gcode_box)
  602. # temporary action until I finish the feature
  603. self.excellon_gcode_type_radio.setVisible(False)
  604. gcode_type_label.hide()
  605. self.generate_cnc_button = QtWidgets.QPushButton('Create GCode')
  606. self.generate_cnc_button.setToolTip(
  607. "Generate the CNC Job."
  608. )
  609. self.tools_box.addWidget(self.generate_cnc_button)
  610. #### Milling Holes Drills####
  611. self.mill_hole_label = QtWidgets.QLabel('<b>Mill Holes</b>')
  612. self.mill_hole_label.setToolTip(
  613. "Create Geometry for milling holes."
  614. )
  615. self.tools_box.addWidget(self.mill_hole_label)
  616. self.choose_tools_label2 = QtWidgets.QLabel(
  617. "Select from the Tools Table above\n"
  618. " the hole dias that are to be milled."
  619. )
  620. self.tools_box.addWidget(self.choose_tools_label2)
  621. grid2 = QtWidgets.QGridLayout()
  622. self.tools_box.addLayout(grid2)
  623. self.tdlabel = QtWidgets.QLabel('Drills Tool dia:')
  624. self.tdlabel.setToolTip(
  625. "Diameter of the cutting tool."
  626. )
  627. grid2.addWidget(self.tdlabel, 0, 0)
  628. self.tooldia_entry = LengthEntry()
  629. grid2.addWidget(self.tooldia_entry, 0, 1)
  630. self.generate_milling_button = QtWidgets.QPushButton('Mill Drills Geo')
  631. self.generate_milling_button.setToolTip(
  632. "Create the Geometry Object\n"
  633. "for milling DRILLS toolpaths."
  634. )
  635. grid2.addWidget(self.generate_milling_button, 0, 2)
  636. grid3 = QtWidgets.QGridLayout()
  637. self.custom_box.addLayout(grid3)
  638. self.stdlabel = QtWidgets.QLabel('Slots Tool dia:')
  639. self.stdlabel.setToolTip(
  640. "Diameter of the cutting tool."
  641. )
  642. grid3.addWidget(self.stdlabel, 0, 0)
  643. self.slot_tooldia_entry = LengthEntry()
  644. grid3.addWidget(self.slot_tooldia_entry, 0, 1)
  645. self.generate_milling_slots_button = QtWidgets.QPushButton('Mill Slots Geo')
  646. self.generate_milling_slots_button.setToolTip(
  647. "Create the Geometry Object\n"
  648. "for milling SLOTS toolpaths."
  649. )
  650. grid3.addWidget(self.generate_milling_slots_button, 0, 2)
  651. def hide_drills(self, state=True):
  652. if state is True:
  653. self.drills_frame.hide()
  654. else:
  655. self.drills_frame.show()
  656. class GeometryObjectUI(ObjectUI):
  657. """
  658. User interface for Geometry objects.
  659. """
  660. def __init__(self, parent=None):
  661. super(GeometryObjectUI, self).__init__(title='Geometry Object', icon_file='share/geometry32.png', parent=parent)
  662. # Plot options
  663. self.plot_options_label = QtWidgets.QLabel("<b>Plot Options:</b>")
  664. self.custom_box.addWidget(self.plot_options_label)
  665. ## Object name
  666. self.name_hlay = QtWidgets.QHBoxLayout()
  667. self.custom_box.addLayout(self.name_hlay)
  668. name_label = QtWidgets.QLabel("<b>Name:</b>")
  669. self.name_entry = FCEntry()
  670. self.name_entry.setFocusPolicy(QtCore.Qt.StrongFocus)
  671. self.name_hlay.addWidget(name_label)
  672. self.name_hlay.addWidget(self.name_entry)
  673. # add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Tools widgets
  674. # this way I can hide/show the frame
  675. self.geo_tools_frame = QtWidgets.QFrame()
  676. self.geo_tools_frame.setContentsMargins(0, 0, 0, 0)
  677. self.custom_box.addWidget(self.geo_tools_frame)
  678. self.geo_tools_box = QtWidgets.QVBoxLayout()
  679. self.geo_tools_box.setContentsMargins(0, 0, 0, 0)
  680. self.geo_tools_frame.setLayout(self.geo_tools_box)
  681. hlay_plot = QtWidgets.QHBoxLayout()
  682. self.geo_tools_box.addLayout(hlay_plot)
  683. #### Tools ####
  684. self.tools_table_label = QtWidgets.QLabel('<b>Tools Table</b>')
  685. self.tools_table_label.setToolTip(
  686. "Tools in this Geometry object used for cutting.\n"
  687. "The 'Offset' entry will set an offset for the cut.\n"
  688. "'Offset' can be inside, outside, on path (none) and custom.\n"
  689. "'Type' entry is only informative and it allow to know the \n"
  690. "intent of using the current tool. \n"
  691. "It can be Rough(ing), Finish(ing) or Iso(lation).\n"
  692. "The 'Tool type'(TT) can be circular with 1 to 4 teeths(C1..C4),\n"
  693. "ball(B), or V-Shaped(V). \n"
  694. "When V-shaped is selected the 'Type' entry is automatically \n"
  695. "set to Isolation, the CutZ parameter in the UI form is\n"
  696. "grayed out and Cut Z is automatically calculated from the newly \n"
  697. "showed UI form entries named V-Tip Dia and V-Tip Angle."
  698. )
  699. hlay_plot.addWidget(self.tools_table_label)
  700. # Plot CB
  701. # self.plot_cb = QtWidgets.QCheckBox('Plot')
  702. self.plot_cb = FCCheckBox('Plot Object')
  703. self.plot_cb.setToolTip(
  704. "Plot (show) this object."
  705. )
  706. self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
  707. hlay_plot.addStretch()
  708. hlay_plot.addWidget(self.plot_cb)
  709. self.geo_tools_table = FCTable()
  710. self.geo_tools_box.addWidget(self.geo_tools_table)
  711. self.geo_tools_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
  712. self.geo_tools_table.setColumnCount(7)
  713. self.geo_tools_table.setColumnWidth(0, 20)
  714. self.geo_tools_table.setHorizontalHeaderLabels(['#', 'Dia', 'Offset', 'Type', 'TT', '', 'P'])
  715. self.geo_tools_table.setColumnHidden(5, True)
  716. # stylesheet = "::section{Background-color:rgb(239,239,245)}"
  717. # self.geo_tools_table.horizontalHeader().setStyleSheet(stylesheet)
  718. self.geo_tools_table.horizontalHeaderItem(0).setToolTip(
  719. "This is the Tool Number.\n"
  720. "When ToolChange is checked, on toolchange event this value\n"
  721. "will be showed as a T1, T2 ... Tn")
  722. self.geo_tools_table.horizontalHeaderItem(1).setToolTip(
  723. "Tool Diameter. It's value (in current FlatCAM units) \n"
  724. "is the cut width into the material.")
  725. self.geo_tools_table.horizontalHeaderItem(2).setToolTip(
  726. "The value for the Offset can be:\n"
  727. "- Path -> There is no offset, the tool cut will be done through the geometry line.\n"
  728. "- In(side) -> The tool cut will follow the geometry inside. It will create a 'pocket'.\n"
  729. "- Out(side) -> The tool cut will follow the geometry line on the outside.")
  730. self.geo_tools_table.horizontalHeaderItem(3).setToolTip(
  731. "The (Operation) Type has only informative value. Usually the UI form values \n"
  732. "are choosed based on the operation type and this will serve as a reminder.\n"
  733. "Can be 'Roughing', 'Finishing' or 'Isolation'.\n"
  734. "For Roughing we may choose a lower Feedrate and multiDepth cut.\n"
  735. "For Finishing we may choose a higher Feedrate, without multiDepth.\n"
  736. "For Isolation we need a lower Feedrate as it use a milling bit with a fine tip.")
  737. self.geo_tools_table.horizontalHeaderItem(4).setToolTip(
  738. "The Tool Type (TT) can be:\n"
  739. "- Circular with 1 ... 4 teeth -> it is informative only. Being circular the cut width in material\n"
  740. "is exactly the tool diameter.\n"
  741. "- Ball -> informative only and make reference to the Ball type endmill.\n"
  742. "- V-Shape -> it will disable de Z-Cut parameter in the UI form and enable two additional UI form\n"
  743. "fields: V-Tip Dia and V-Tip Angle. Adjusting those two values will adjust the Z-Cut parameter such\n"
  744. "as the cut width into material will be equal with the value in the Tool Diameter column of this table.\n"
  745. "Choosing the V-Shape Tool Type automatically will select the Operation Type as Isolation.")
  746. self.geo_tools_table.horizontalHeaderItem(6).setToolTip(
  747. "Plot column. It is visible only for MultiGeo geometries, meaning geometries that holds the geometry\n"
  748. "data into the tools. For those geometries, deleting the tool will delete the geometry data also,\n"
  749. "so be WARNED. From the checkboxes on each row it can be enabled/disabled the plot on canvas\n"
  750. "for the corresponding tool.")
  751. # self.geo_tools_table.setSortingEnabled(False)
  752. # self.geo_tools_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
  753. # Tool Offset
  754. self.grid1 = QtWidgets.QGridLayout()
  755. self.geo_tools_box.addLayout(self.grid1)
  756. self.tool_offset_lbl = QtWidgets.QLabel('Tool Offset:')
  757. self.tool_offset_lbl.setToolTip(
  758. "The value to offset the cut when \n"
  759. "the Offset type selected is 'Offset'.\n"
  760. "The value can be positive for 'outside'\n"
  761. "cut and negative for 'inside' cut."
  762. )
  763. self.grid1.addWidget(self.tool_offset_lbl, 0, 0)
  764. self.tool_offset_entry = FloatEntry()
  765. self.tool_offset_entry.setValidator(QtGui.QDoubleValidator(-9999.9999, 9999.9999, 4))
  766. spacer_lbl = QtWidgets.QLabel(" ")
  767. spacer_lbl.setFixedWidth(80)
  768. self.grid1.addWidget(self.tool_offset_entry, 0, 1)
  769. self.grid1.addWidget(spacer_lbl, 0, 2)
  770. #### Add a new Tool ####
  771. hlay = QtWidgets.QHBoxLayout()
  772. self.geo_tools_box.addLayout(hlay)
  773. # self.addtool_label = QtWidgets.QLabel('<b>Tool</b>')
  774. # self.addtool_label.setToolTip(
  775. # "Add/Copy/Delete a tool to the tool list."
  776. # )
  777. self.addtool_entry_lbl = QtWidgets.QLabel('<b>Tool Dia:</b>')
  778. self.addtool_entry_lbl.setToolTip(
  779. "Diameter for the new tool"
  780. )
  781. self.addtool_entry = FCEntry()
  782. # hlay.addWidget(self.addtool_label)
  783. # hlay.addStretch()
  784. hlay.addWidget(self.addtool_entry_lbl)
  785. hlay.addWidget(self.addtool_entry)
  786. grid2 = QtWidgets.QGridLayout()
  787. self.geo_tools_box.addLayout(grid2)
  788. self.addtool_btn = QtWidgets.QPushButton('Add')
  789. self.addtool_btn.setToolTip(
  790. "Add a new tool to the Tool Table\n"
  791. "with the diameter specified above."
  792. )
  793. self.copytool_btn = QtWidgets.QPushButton('Copy')
  794. self.copytool_btn.setToolTip(
  795. "Copy a selection of tools in the Tool Table\n"
  796. "by first selecting a row in the Tool Table."
  797. )
  798. self.deltool_btn = QtWidgets.QPushButton('Delete')
  799. self.deltool_btn.setToolTip(
  800. "Delete a selection of tools in the Tool Table\n"
  801. "by first selecting a row in the Tool Table."
  802. )
  803. grid2.addWidget(self.addtool_btn, 0, 0)
  804. grid2.addWidget(self.copytool_btn, 0, 1)
  805. grid2.addWidget(self.deltool_btn, 0,2)
  806. self.empty_label = QtWidgets.QLabel('')
  807. self.geo_tools_box.addWidget(self.empty_label)
  808. #-----------------------------------
  809. # Create CNC Job
  810. #-----------------------------------
  811. #### Tools Data ####
  812. self.tool_data_label = QtWidgets.QLabel('<b>Tool Data</b>')
  813. self.tool_data_label.setToolTip(
  814. "The data used for creating GCode.\n"
  815. "Each tool store it's own set of such data."
  816. )
  817. self.geo_tools_box.addWidget(self.tool_data_label)
  818. self.grid3 = QtWidgets.QGridLayout()
  819. self.geo_tools_box.addLayout(self.grid3)
  820. # Tip Dia
  821. self.tipdialabel = QtWidgets.QLabel('V-Tip Dia:')
  822. self.tipdialabel.setToolTip(
  823. "The tip diameter for V-Shape Tool"
  824. )
  825. self.grid3.addWidget(self.tipdialabel, 1, 0)
  826. self.tipdia_entry = LengthEntry()
  827. self.grid3.addWidget(self.tipdia_entry, 1, 1)
  828. # Tip Angle
  829. self.tipanglelabel = QtWidgets.QLabel('V-Tip Angle:')
  830. self.tipanglelabel.setToolTip(
  831. "The tip angle for V-Shape Tool.\n"
  832. "In degree."
  833. )
  834. self.grid3.addWidget(self.tipanglelabel, 2, 0)
  835. self.tipangle_entry = LengthEntry()
  836. self.grid3.addWidget(self.tipangle_entry, 2, 1)
  837. # Cut Z
  838. cutzlabel = QtWidgets.QLabel('Cut Z:')
  839. cutzlabel.setToolTip(
  840. "Cutting depth (negative)\n"
  841. "below the copper surface."
  842. )
  843. self.grid3.addWidget(cutzlabel, 3, 0)
  844. self.cutz_entry = LengthEntry()
  845. self.grid3.addWidget(self.cutz_entry, 3, 1)
  846. # Multi-pass
  847. self.mpass_cb = FCCheckBox("Multi-Depth:")
  848. self.mpass_cb.setToolTip(
  849. "Use multiple passes to limit\n"
  850. "the cut depth in each pass. Will\n"
  851. "cut multiple times until Cut Z is\n"
  852. "reached.\n"
  853. "To the right, input the depth of \n"
  854. "each pass (positive value)."
  855. )
  856. self.grid3.addWidget(self.mpass_cb, 4, 0)
  857. self.maxdepth_entry = LengthEntry()
  858. self.maxdepth_entry.setToolTip(
  859. "Depth of each pass (positive)."
  860. )
  861. self.grid3.addWidget(self.maxdepth_entry, 4, 1)
  862. self.ois_mpass_geo = OptionalInputSection(self.mpass_cb, [self.maxdepth_entry])
  863. # Travel Z
  864. travelzlabel = QtWidgets.QLabel('Travel Z:')
  865. travelzlabel.setToolTip(
  866. "Height of the tool when\n"
  867. "moving without cutting."
  868. )
  869. self.grid3.addWidget(travelzlabel, 5, 0)
  870. self.travelz_entry = LengthEntry()
  871. self.grid3.addWidget(self.travelz_entry, 5, 1)
  872. # Tool change:
  873. self.toolchzlabel = QtWidgets.QLabel("Tool change Z:")
  874. self.toolchzlabel.setToolTip(
  875. "Z-axis position (height) for\n"
  876. "tool change."
  877. )
  878. self.toolchangeg_cb = FCCheckBox("Tool change")
  879. self.toolchangeg_cb.setToolTip(
  880. "Include tool-change sequence\n"
  881. "in the Machine Code (Pause for tool change)."
  882. )
  883. self.toolchangez_entry = LengthEntry()
  884. self.grid3.addWidget(self.toolchangeg_cb, 6, 0)
  885. self.grid3.addWidget(self.toolchzlabel, 7, 0)
  886. self.grid3.addWidget(self.toolchangez_entry, 7, 1)
  887. self.ois_tcz_geo = OptionalInputSection(self.toolchangeg_cb, [self.toolchangez_entry])
  888. # The Z value for the start move
  889. # startzlabel = QtWidgets.QLabel('Start move Z:')
  890. # startzlabel.setToolTip(
  891. # "Tool height just before starting the work.\n"
  892. # "Delete the value if you don't need this feature."
  893. #
  894. # )
  895. # self.grid3.addWidget(startzlabel, 8, 0)
  896. # self.gstartz_entry = FloatEntry()
  897. # self.grid3.addWidget(self.gstartz_entry, 8, 1)
  898. # The Z value for the end move
  899. self.endzlabel = QtWidgets.QLabel('End move Z:')
  900. self.endzlabel.setToolTip(
  901. "This is the height (Z) at which the CNC\n"
  902. "will go as the last move."
  903. )
  904. self.grid3.addWidget(self.endzlabel, 9, 0)
  905. self.gendz_entry = LengthEntry()
  906. self.grid3.addWidget(self.gendz_entry, 9, 1)
  907. # Feedrate X-Y
  908. frlabel = QtWidgets.QLabel('Feed Rate X-Y:')
  909. frlabel.setToolTip(
  910. "Cutting speed in the XY\n"
  911. "plane in units per minute"
  912. )
  913. self.grid3.addWidget(frlabel, 10, 0)
  914. self.cncfeedrate_entry = LengthEntry()
  915. self.grid3.addWidget(self.cncfeedrate_entry, 10, 1)
  916. # Feedrate Z (Plunge)
  917. frzlabel = QtWidgets.QLabel('Feed Rate Z (Plunge):')
  918. frzlabel.setToolTip(
  919. "Cutting speed in the Z\n"
  920. "plane in units per minute"
  921. )
  922. self.grid3.addWidget(frzlabel, 11, 0)
  923. self.cncplunge_entry = LengthEntry()
  924. self.grid3.addWidget(self.cncplunge_entry, 11, 1)
  925. # Feedrate rapids
  926. self.fr_rapidlabel = QtWidgets.QLabel('Feed Rate Rapids:')
  927. self.fr_rapidlabel.setToolTip(
  928. "Cutting speed in the XY\n"
  929. "plane in units per minute\n"
  930. "for the rapid movements"
  931. )
  932. self.grid3.addWidget(self.fr_rapidlabel, 12, 0)
  933. self.cncfeedrate_rapid_entry = LengthEntry()
  934. self.grid3.addWidget(self.cncfeedrate_rapid_entry, 12, 1)
  935. # Cut over 1st point in path
  936. self.extracut_cb = FCCheckBox('Cut over 1st pt')
  937. self.extracut_cb.setToolTip(
  938. "In order to remove possible\n"
  939. "copper leftovers where first cut\n"
  940. "meet with last cut, we generate an\n"
  941. "extended cut over the first cut section."
  942. )
  943. self.grid3.addWidget(self.extracut_cb, 13, 0)
  944. # Spindlespeed
  945. spdlabel = QtWidgets.QLabel('Spindle speed:')
  946. spdlabel.setToolTip(
  947. "Speed of the spindle in RPM (optional).\n"
  948. "If LASER postprocessor is used,\n"
  949. "this value is the power of laser."
  950. )
  951. self.grid3.addWidget(spdlabel, 14, 0)
  952. self.cncspindlespeed_entry = IntEntry(allow_empty=True)
  953. self.grid3.addWidget(self.cncspindlespeed_entry, 14, 1)
  954. # Dwell
  955. self.dwell_cb = FCCheckBox('Dwell:')
  956. self.dwell_cb.setToolTip(
  957. "Pause to allow the spindle to reach its\n"
  958. "speed before cutting."
  959. )
  960. self.dwelltime_entry = FCEntry()
  961. self.dwelltime_entry.setToolTip(
  962. "Number of milliseconds for spindle to dwell."
  963. )
  964. self.grid3.addWidget(self.dwell_cb, 15, 0)
  965. self.grid3.addWidget(self.dwelltime_entry, 15, 1)
  966. self.ois_dwell_geo = OptionalInputSection(self.dwell_cb, [self.dwelltime_entry])
  967. # postprocessor selection
  968. pp_label = QtWidgets.QLabel("PostProcessor:")
  969. pp_label.setToolTip(
  970. "The Postprocessor file that dictates\n"
  971. "the Machine Code (like GCode, RML, HPGL) output."
  972. )
  973. self.grid3.addWidget(pp_label, 16, 0)
  974. self.pp_geometry_name_cb = FCComboBox()
  975. self.pp_geometry_name_cb.setFocusPolicy(QtCore.Qt.StrongFocus)
  976. self.grid3.addWidget(self.pp_geometry_name_cb, 16, 1)
  977. # Probe depth
  978. self.pdepth_label = QtWidgets.QLabel("Probe Z depth:")
  979. self.pdepth_label.setToolTip(
  980. "The maximum depth that the probe is allowed\n"
  981. "to probe. Negative value, in current units."
  982. )
  983. self.grid3.addWidget(self.pdepth_label, 17, 0)
  984. self.pdepth_entry = FCEntry()
  985. self.grid3.addWidget(self.pdepth_entry, 17, 1)
  986. self.pdepth_label.hide()
  987. self.pdepth_entry.setVisible(False)
  988. # Probe feedrate
  989. self.feedrate_probe_label = QtWidgets.QLabel("Feedrate Probe:")
  990. self.feedrate_probe_label.setToolTip(
  991. "The feedrate used while the probe is probing."
  992. )
  993. self.grid3.addWidget(self.feedrate_probe_label, 18, 0)
  994. self.feedrate_probe_entry = FCEntry()
  995. self.grid3.addWidget(self.feedrate_probe_entry, 18, 1)
  996. self.feedrate_probe_label.hide()
  997. self.feedrate_probe_entry.setVisible(False)
  998. warning_lbl = QtWidgets.QLabel(
  999. "Add at least one tool in the tool-table.\n"
  1000. "Click the header to select all, or Ctrl + LMB\n"
  1001. "for custom selection of tools.")
  1002. self.grid3.addWidget(warning_lbl, 19, 0, 1, 2)
  1003. # Button
  1004. self.generate_cnc_button = QtWidgets.QPushButton('Generate')
  1005. self.generate_cnc_button.setToolTip(
  1006. "Generate the CNC Job object."
  1007. )
  1008. self.geo_tools_box.addWidget(self.generate_cnc_button)
  1009. #------------------------------
  1010. # Paint area
  1011. #------------------------------
  1012. self.paint_label = QtWidgets.QLabel('<b>Paint Area:</b>')
  1013. self.paint_label.setToolTip(
  1014. "Creates tool paths to cover the\n"
  1015. "whole area of a polygon (remove\n"
  1016. "all copper). You will be asked\n"
  1017. "to click on the desired polygon."
  1018. )
  1019. self.geo_tools_box.addWidget(self.paint_label)
  1020. # GO Button
  1021. self.paint_tool_button = QtWidgets.QPushButton('Paint Tool')
  1022. self.paint_tool_button.setToolTip(
  1023. "Launch Paint Tool in Tools Tab."
  1024. )
  1025. self.geo_tools_box.addWidget(self.paint_tool_button)
  1026. class CNCObjectUI(ObjectUI):
  1027. """
  1028. User interface for CNCJob objects.
  1029. """
  1030. def __init__(self, parent=None):
  1031. """
  1032. Creates the user interface for CNCJob objects. GUI elements should
  1033. be placed in ``self.custom_box`` to preserve the layout.
  1034. """
  1035. ObjectUI.__init__(self, title='CNC Job Object', icon_file='share/cnc32.png', parent=parent)
  1036. # Scale and offset ans skew are not available for CNCJob objects.
  1037. # Hiding from the GUI.
  1038. for i in range(0, self.scale_grid.count()):
  1039. self.scale_grid.itemAt(i).widget().hide()
  1040. self.scale_label.hide()
  1041. self.scale_button.hide()
  1042. for i in range(0, self.offset_grid.count()):
  1043. self.offset_grid.itemAt(i).widget().hide()
  1044. self.offset_label.hide()
  1045. self.offset_button.hide()
  1046. ## Plot options
  1047. self.plot_options_label = QtWidgets.QLabel("<b>Plot Options:</b>")
  1048. self.custom_box.addWidget(self.plot_options_label)
  1049. self.cncplot_method_label = QtWidgets.QLabel("<b>Plot kind:</b>")
  1050. self.cncplot_method_label.setToolTip(
  1051. "This selects the kind of geometries on the canvas to plot.\n"
  1052. "Those can be either of type 'Travel' which means the moves\n"
  1053. "above the work piece or it can be of type 'Cut',\n"
  1054. "which means the moves that cut into the material."
  1055. )
  1056. self.cncplot_method_combo = RadioSet([
  1057. {"label": "All", "value": "all"},
  1058. {"label": "Travel", "value": "travel"},
  1059. {"label": "Cut", "value": "cut"}
  1060. ], stretch=False)
  1061. ## Object name
  1062. self.name_hlay = QtWidgets.QHBoxLayout()
  1063. self.custom_box.addLayout(self.name_hlay)
  1064. name_label = QtWidgets.QLabel("<b>Name:</b>")
  1065. self.name_entry = FCEntry()
  1066. self.name_entry.setFocusPolicy(QtCore.Qt.StrongFocus)
  1067. self.name_hlay.addWidget(name_label)
  1068. self.name_hlay.addWidget(self.name_entry)
  1069. self.t_distance_label = QtWidgets.QLabel("<b>Travelled dist.:</b>")
  1070. self.t_distance_label.setToolTip(
  1071. "This is the total travelled distance on X-Y plane.\n"
  1072. "In current units."
  1073. )
  1074. self.t_distance_entry = FCEntry()
  1075. self.t_distance_entry.setToolTip(
  1076. "This is the total travelled distance on X-Y plane.\n"
  1077. "In current units."
  1078. )
  1079. self.units_label = QtWidgets.QLabel()
  1080. f_lay = QtWidgets.QGridLayout()
  1081. f_lay.setColumnStretch(1, 1)
  1082. f_lay.setColumnStretch(2, 1)
  1083. self.custom_box.addLayout(f_lay)
  1084. f_lay.addWidget(self.cncplot_method_label, 0, 0)
  1085. f_lay.addWidget(self.cncplot_method_combo, 0, 1)
  1086. f_lay.addWidget(QtWidgets.QLabel(''), 0, 2)
  1087. f_lay.addWidget(self.t_distance_label, 1, 0)
  1088. f_lay.addWidget(self.t_distance_entry, 1, 1)
  1089. f_lay.addWidget(self.units_label, 1, 2)
  1090. self.t_distance_label.hide()
  1091. self.t_distance_entry.setVisible(False)
  1092. e1_lbl = QtWidgets.QLabel('')
  1093. self.custom_box.addWidget(e1_lbl)
  1094. hlay = QtWidgets.QHBoxLayout()
  1095. self.custom_box.addLayout(hlay)
  1096. # CNC Tools Table for plot
  1097. self.cnc_tools_table_label = QtWidgets.QLabel('<b>CNC Tools Table</b>')
  1098. self.cnc_tools_table_label.setToolTip(
  1099. "Tools in this CNCJob object used for cutting.\n"
  1100. "The tool diameter is used for plotting on canvas.\n"
  1101. "The 'Offset' entry will set an offset for the cut.\n"
  1102. "'Offset' can be inside, outside, on path (none) and custom.\n"
  1103. "'Type' entry is only informative and it allow to know the \n"
  1104. "intent of using the current tool. \n"
  1105. "It can be Rough(ing), Finish(ing) or Iso(lation).\n"
  1106. "The 'Tool type'(TT) can be circular with 1 to 4 teeths(C1..C4),\n"
  1107. "ball(B), or V-Shaped(V)."
  1108. )
  1109. hlay.addWidget(self.cnc_tools_table_label)
  1110. # Plot CB
  1111. # self.plot_cb = QtWidgets.QCheckBox('Plot')
  1112. self.plot_cb = FCCheckBox('Plot Object')
  1113. self.plot_cb.setToolTip(
  1114. "Plot (show) this object."
  1115. )
  1116. self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
  1117. hlay.addStretch()
  1118. hlay.addWidget(self.plot_cb)
  1119. self.cnc_tools_table = FCTable()
  1120. self.custom_box.addWidget(self.cnc_tools_table)
  1121. # self.cnc_tools_table.setColumnCount(4)
  1122. # self.cnc_tools_table.setHorizontalHeaderLabels(['#', 'Dia', 'Plot', ''])
  1123. # self.cnc_tools_table.setColumnHidden(3, True)
  1124. self.cnc_tools_table.setColumnCount(7)
  1125. self.cnc_tools_table.setColumnWidth(0, 20)
  1126. self.cnc_tools_table.setHorizontalHeaderLabels(['#', 'Dia', 'Offset', 'Type', 'TT', '', 'P'])
  1127. self.cnc_tools_table.setColumnHidden(5, True)
  1128. # stylesheet = "::section{Background-color:rgb(239,239,245)}"
  1129. # self.cnc_tools_table.horizontalHeader().setStyleSheet(stylesheet)
  1130. # Update plot button
  1131. self.updateplot_button = QtWidgets.QPushButton('Update Plot')
  1132. self.updateplot_button.setToolTip(
  1133. "Update the plot."
  1134. )
  1135. self.custom_box.addWidget(self.updateplot_button)
  1136. ##################
  1137. ## Export G-Code
  1138. ##################
  1139. self.export_gcode_label = QtWidgets.QLabel("<b>Export CNC Code:</b>")
  1140. self.export_gcode_label.setToolTip(
  1141. "Export and save G-Code to\n"
  1142. "make this object to a file."
  1143. )
  1144. self.custom_box.addWidget(self.export_gcode_label)
  1145. # Prepend text to Gerber
  1146. prependlabel = QtWidgets.QLabel('Prepend to CNC Code:')
  1147. prependlabel.setToolTip(
  1148. "Type here any G-Code commands you would\n"
  1149. "like to add to the beginning of the generated file."
  1150. )
  1151. self.custom_box.addWidget(prependlabel)
  1152. self.prepend_text = FCTextArea()
  1153. self.custom_box.addWidget(self.prepend_text)
  1154. # Append text to Gerber
  1155. appendlabel = QtWidgets.QLabel('Append to CNC Code')
  1156. appendlabel.setToolTip(
  1157. "Type here any G-Code commands you would\n"
  1158. "like to append to the generated file.\n"
  1159. "I.e.: M2 (End of program)"
  1160. )
  1161. self.custom_box.addWidget(appendlabel)
  1162. self.append_text = FCTextArea()
  1163. self.custom_box.addWidget(self.append_text)
  1164. h_lay = QtWidgets.QHBoxLayout()
  1165. h_lay.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
  1166. self.custom_box.addLayout(h_lay)
  1167. # Edit GCode Button
  1168. self.modify_gcode_button = QtWidgets.QPushButton('View CNC Code')
  1169. self.modify_gcode_button.setToolTip(
  1170. "Opens TAB to view/modify/print G-Code\n"
  1171. "file."
  1172. )
  1173. # GO Button
  1174. self.export_gcode_button = QtWidgets.QPushButton('Save CNC Code')
  1175. self.export_gcode_button.setToolTip(
  1176. "Opens dialog to save G-Code\n"
  1177. "file."
  1178. )
  1179. h_lay.addWidget(self.modify_gcode_button)
  1180. h_lay.addWidget(self.export_gcode_button)
  1181. # self.custom_box.addWidget(self.export_gcode_button)
  1182. # end of file