ObjectUI.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. import sys
  2. from PyQt4 import QtGui, QtCore
  3. from GUIElements import *
  4. class ObjectUI(QtGui.QWidget):
  5. """
  6. Base class for the UI of FlatCAM objects. Deriving classes should
  7. put UI elements in ObjectUI.custom_box (QtGui.QLayout).
  8. """
  9. def __init__(self, icon_file='share/flatcam_icon32.png', title='FlatCAM Object', parent=None):
  10. QtGui.QWidget.__init__(self, parent=parent)
  11. layout = QtGui.QVBoxLayout()
  12. self.setLayout(layout)
  13. ## Page Title box (spacing between children)
  14. self.title_box = QtGui.QHBoxLayout()
  15. layout.addLayout(self.title_box)
  16. ## Page Title icon
  17. pixmap = QtGui.QPixmap(icon_file)
  18. self.icon = QtGui.QLabel()
  19. self.icon.setPixmap(pixmap)
  20. self.title_box.addWidget(self.icon, stretch=0)
  21. ## Title label
  22. self.title_label = QtGui.QLabel("<font size=5><b>" + title + "</b></font>")
  23. self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  24. self.title_box.addWidget(self.title_label, stretch=1)
  25. ## Object name
  26. self.name_box = QtGui.QHBoxLayout()
  27. layout.addLayout(self.name_box)
  28. name_label = QtGui.QLabel("Name:")
  29. self.name_box.addWidget(name_label)
  30. self.name_entry = FCEntry()
  31. self.name_box.addWidget(self.name_entry)
  32. ## Box box for custom widgets
  33. self.custom_box = QtGui.QVBoxLayout()
  34. layout.addLayout(self.custom_box)
  35. ## Common to all objects
  36. ## Scale
  37. self.scale_label = QtGui.QLabel('<b>Scale:</b>')
  38. self.scale_label.setToolTip(
  39. "Change the size of the object."
  40. )
  41. layout.addWidget(self.scale_label)
  42. grid1 = QtGui.QGridLayout()
  43. layout.addLayout(grid1)
  44. # Factor
  45. faclabel = QtGui.QLabel('Factor:')
  46. faclabel.setToolTip(
  47. "Factor by which to multiply\n"
  48. "geometric features of this object."
  49. )
  50. grid1.addWidget(faclabel, 0, 0)
  51. self.scale_entry = FloatEntry()
  52. self.scale_entry.set_value(1.0)
  53. grid1.addWidget(self.scale_entry, 0, 1)
  54. # GO Button
  55. self.scale_button = QtGui.QPushButton('Scale')
  56. self.scale_button.setToolTip(
  57. "Perform scaling operation."
  58. )
  59. layout.addWidget(self.scale_button)
  60. ## Offset
  61. self.offset_label = QtGui.QLabel('<b>Offset:</b>')
  62. self.offset_label.setToolTip(
  63. "Change the position of this object."
  64. )
  65. layout.addWidget(self.offset_label)
  66. grid2 = QtGui.QGridLayout()
  67. layout.addLayout(grid2)
  68. self.offset_label = QtGui.QLabel('Vector:')
  69. self.offset_label.setToolTip(
  70. "Amount by which to move the object\n"
  71. "in the x and y axes in (x, y) format."
  72. )
  73. grid2.addWidget(self.offset_label, 0, 0)
  74. self.offsetvector_entry = EvalEntry()
  75. self.offsetvector_entry.setText("(0.0, 0.0)")
  76. grid2.addWidget(self.offsetvector_entry, 0, 1)
  77. self.offset_button = QtGui.QPushButton('Offset')
  78. self.offset_button.setToolTip(
  79. "Perform the offset operation."
  80. )
  81. layout.addWidget(self.offset_button)
  82. layout.addStretch()
  83. class CNCObjectUI(ObjectUI):
  84. """
  85. User interface for CNCJob objects.
  86. """
  87. def __init__(self, parent=None):
  88. ObjectUI.__init__(self, title='CNC Job Object', icon_file='share/cnc32.png', parent=parent)
  89. ## Plot options
  90. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  91. self.custom_box.addWidget(self.plot_options_label)
  92. grid0 = QtGui.QGridLayout()
  93. self.custom_box.addLayout(grid0)
  94. # Plot CB
  95. # self.plot_cb = QtGui.QCheckBox('Plot')
  96. self.plot_cb = FCCheckBox('Plot')
  97. self.plot_cb.setToolTip(
  98. "Plot (show) this object."
  99. )
  100. grid0.addWidget(self.plot_cb, 0, 0)
  101. # Tool dia for plot
  102. tdlabel = QtGui.QLabel('Tool dia:')
  103. tdlabel.setToolTip(
  104. "Diameter of the tool to be\n"
  105. "rendered in the plot."
  106. )
  107. grid0.addWidget(tdlabel, 1, 0)
  108. self.tooldia_entry = LengthEntry()
  109. grid0.addWidget(self.tooldia_entry, 1, 1)
  110. # Update plot button
  111. self.updateplot_button = QtGui.QPushButton('Update Plot')
  112. self.updateplot_button.setToolTip(
  113. "Update the plot."
  114. )
  115. self.custom_box.addWidget(self.updateplot_button)
  116. ## Export G-Code
  117. self.export_gcode_label = QtGui.QLabel("<b>Export G-Code:</b>")
  118. self.export_gcode_label.setToolTip(
  119. "Export and save G-Code to\n"
  120. "make this object to a file."
  121. )
  122. self.custom_box.addWidget(self.export_gcode_label)
  123. # Append text to Gerber
  124. appendlabel = QtGui.QLabel('Append to G-Code:')
  125. appendlabel.setToolTip(
  126. "Type here any G-Code commands you would\n"
  127. "like to append to the generated file.\n"
  128. "I.e.: M2 (End of program)"
  129. )
  130. self.custom_box.addWidget(appendlabel)
  131. self.append_text = FCTextArea()
  132. self.custom_box.addWidget(self.append_text)
  133. # GO Button
  134. self.export_gcode_button = QtGui.QPushButton('Export G-Code')
  135. self.export_gcode_button.setToolTip(
  136. "Opens dialog to save G-Code\n"
  137. "file."
  138. )
  139. self.custom_box.addWidget(self.export_gcode_button)
  140. class GeometryObjectUI(ObjectUI):
  141. """
  142. User interface for Geometry objects.
  143. """
  144. def __init__(self, parent=None):
  145. super(GeometryObjectUI, self).__init__(title='Geometry Object', icon_file='share/geometry32.png', parent=parent)
  146. ## Plot options
  147. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  148. self.custom_box.addWidget(self.plot_options_label)
  149. # Plot CB
  150. self.plot_cb = FCCheckBox(label='Plot')
  151. self.plot_cb.setToolTip(
  152. "Plot (show) this object."
  153. )
  154. self.custom_box.addWidget(self.plot_cb)
  155. ## Create CNC Job
  156. self.cncjob_label = QtGui.QLabel('<b>Create CNC Job:</b>')
  157. self.cncjob_label.setToolTip(
  158. "Create a CNC Job object\n"
  159. "tracing the contours of this\n"
  160. "Geometry object."
  161. )
  162. self.custom_box.addWidget(self.cncjob_label)
  163. grid1 = QtGui.QGridLayout()
  164. self.custom_box.addLayout(grid1)
  165. cutzlabel = QtGui.QLabel('Cut Z:')
  166. cutzlabel.setToolTip(
  167. "Cutting depth (negative)\n"
  168. "below the copper surface."
  169. )
  170. grid1.addWidget(cutzlabel, 0, 0)
  171. self.cutz_entry = LengthEntry()
  172. grid1.addWidget(self.cutz_entry, 0, 1)
  173. # Travel Z
  174. travelzlabel = QtGui.QLabel('Travel Z:')
  175. travelzlabel.setToolTip(
  176. "Height of the tool when\n"
  177. "moving without cutting."
  178. )
  179. grid1.addWidget(travelzlabel, 1, 0)
  180. self.travelz_entry = LengthEntry()
  181. grid1.addWidget(self.travelz_entry, 1, 1)
  182. # Feedrate
  183. frlabel = QtGui.QLabel('Feed Rate:')
  184. frlabel.setToolTip(
  185. "Cutting speed in the XY\n"
  186. "plane in units per minute"
  187. )
  188. grid1.addWidget(frlabel, 2, 0)
  189. self.cncfeedrate_entry = LengthEntry()
  190. grid1.addWidget(self.cncfeedrate_entry, 2, 1)
  191. # Tooldia
  192. tdlabel = QtGui.QLabel('Tool dia:')
  193. tdlabel.setToolTip(
  194. "The diameter of the cutting\n"
  195. "tool (just for display)."
  196. )
  197. grid1.addWidget(tdlabel, 3, 0)
  198. self.cnctooldia_entry = LengthEntry()
  199. grid1.addWidget(self.cnctooldia_entry, 3, 1)
  200. self.generate_cnc_button = QtGui.QPushButton('Generate')
  201. self.generate_cnc_button.setToolTip(
  202. "Generate the CNC Job object."
  203. )
  204. self.custom_box.addWidget(self.generate_cnc_button)
  205. ## Paint area
  206. self.paint_label = QtGui.QLabel('<b>Paint Area:</b>')
  207. self.paint_label.setToolTip(
  208. "Creates tool paths to cover the\n"
  209. "whole area of a polygon (remove\n"
  210. "all copper). You will be asked\n"
  211. "to click on the desired polygon."
  212. )
  213. self.custom_box.addWidget(self.paint_label)
  214. grid2 = QtGui.QGridLayout()
  215. self.custom_box.addLayout(grid2)
  216. # Tool dia
  217. ptdlabel = QtGui.QLabel('Tool dia:')
  218. ptdlabel.setToolTip(
  219. "Diameter of the tool to\n"
  220. "be used in the operation."
  221. )
  222. grid2.addWidget(ptdlabel, 0, 0)
  223. self.painttooldia_entry = LengthEntry()
  224. grid2.addWidget(self.painttooldia_entry, 0, 1)
  225. # Overlap
  226. ovlabel = QtGui.QLabel('Overlap:')
  227. ovlabel.setToolTip(
  228. "How much (fraction) of the tool\n"
  229. "width to overlap each tool pass."
  230. )
  231. grid2.addWidget(ovlabel, 1, 0)
  232. self.paintoverlap_entry = LengthEntry()
  233. grid2.addWidget(self.paintoverlap_entry, 1, 1)
  234. # Margin
  235. marginlabel = QtGui.QLabel('Margin:')
  236. marginlabel.setToolTip(
  237. "Distance by which to avoid\n"
  238. "the edges of the polygon to\n"
  239. "be painted."
  240. )
  241. grid2.addWidget(marginlabel, 2, 0)
  242. self.paintmargin_entry = LengthEntry()
  243. grid2.addWidget(self.paintmargin_entry)
  244. # GO Button
  245. self.generate_paint_button = QtGui.QPushButton('Generate')
  246. self.generate_paint_button.setToolTip(
  247. "After clicking here, click inside\n"
  248. "the polygon you wish to be painted.\n"
  249. "A new Geometry object with the tool\n"
  250. "paths will be created."
  251. )
  252. self.custom_box.addWidget(self.generate_paint_button)
  253. class ExcellonObjectUI(ObjectUI):
  254. """
  255. User interface for Excellon objects.
  256. """
  257. def __init__(self, parent=None):
  258. ObjectUI.__init__(self, title='Excellon Object', icon_file='share/drill32.png', parent=parent)
  259. ## Plot options
  260. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  261. self.custom_box.addWidget(self.plot_options_label)
  262. grid0 = QtGui.QGridLayout()
  263. self.custom_box.addLayout(grid0)
  264. self.plot_cb = FCCheckBox(label='Plot')
  265. self.plot_cb.setToolTip(
  266. "Plot (show) this object."
  267. )
  268. grid0.addWidget(self.plot_cb, 0, 0)
  269. self.solid_cb = FCCheckBox(label='Solid')
  270. self.solid_cb.setToolTip(
  271. "Solid circles."
  272. )
  273. grid0.addWidget(self.solid_cb, 0, 1)
  274. ## Tools
  275. self.tools_table_label = QtGui.QLabel('<b>Tools</b>')
  276. self.tools_table_label.setToolTip(
  277. "Tools in this Excellon object."
  278. )
  279. self.custom_box.addWidget(self.tools_table_label)
  280. self.tools_table = QtGui.QTableWidget()
  281. self.tools_table.setFixedHeight(100)
  282. self.custom_box.addWidget(self.tools_table)
  283. ## Create CNC Job
  284. self.cncjob_label = QtGui.QLabel('<b>Create CNC Job</b>')
  285. self.cncjob_label.setToolTip(
  286. "Create a CNC Job object\n"
  287. "for this drill object."
  288. )
  289. self.custom_box.addWidget(self.cncjob_label)
  290. grid1 = QtGui.QGridLayout()
  291. self.custom_box.addLayout(grid1)
  292. cutzlabel = QtGui.QLabel('Cut Z:')
  293. cutzlabel.setToolTip(
  294. "Drill depth (negative)\n"
  295. "below the copper surface."
  296. )
  297. grid1.addWidget(cutzlabel, 0, 0)
  298. self.cutz_entry = LengthEntry()
  299. grid1.addWidget(self.cutz_entry, 0, 1)
  300. travelzlabel = QtGui.QLabel('Travel Z:')
  301. travelzlabel.setToolTip(
  302. "Tool height when travelling\n"
  303. "across the XY plane."
  304. )
  305. grid1.addWidget(travelzlabel, 1, 0)
  306. self.travelz_entry = LengthEntry()
  307. grid1.addWidget(self.travelz_entry, 1, 1)
  308. frlabel = QtGui.QLabel('Feed rate:')
  309. frlabel.setToolTip(
  310. "Tool speed while drilling\n"
  311. "(in units per minute)."
  312. )
  313. grid1.addWidget(frlabel, 2, 0)
  314. self.feedrate_entry = LengthEntry()
  315. grid1.addWidget(self.feedrate_entry, 2, 1)
  316. choose_tools_label = QtGui.QLabel(
  317. "Select from the tools section above\n"
  318. "the tools you want to include."
  319. )
  320. self.custom_box.addWidget(choose_tools_label)
  321. self.generate_cnc_button = QtGui.QPushButton('Generate')
  322. self.generate_cnc_button.setToolTip(
  323. "Generate the CNC Job."
  324. )
  325. self.custom_box.addWidget(self.generate_cnc_button)
  326. class GerberObjectUI(ObjectUI):
  327. """
  328. User interface for Gerber objects.
  329. """
  330. def __init__(self, parent=None):
  331. ObjectUI.__init__(self, title='Gerber Object', parent=parent)
  332. ## Plot options
  333. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  334. self.custom_box.addWidget(self.plot_options_label)
  335. grid0 = QtGui.QGridLayout()
  336. self.custom_box.addLayout(grid0)
  337. # Plot CB
  338. self.plot_cb = FCCheckBox(label='Plot')
  339. self.plot_options_label.setToolTip(
  340. "Plot (show) this object."
  341. )
  342. grid0.addWidget(self.plot_cb, 0, 0)
  343. # Solid CB
  344. self.solid_cb = FCCheckBox(label='Solid')
  345. self.solid_cb.setToolTip(
  346. "Solid color polygons."
  347. )
  348. grid0.addWidget(self.solid_cb, 0, 1)
  349. # Multicolored CB
  350. self.multicolored_cb = FCCheckBox(label='Multicolored')
  351. self.multicolored_cb.setToolTip(
  352. "Draw polygons in different colors."
  353. )
  354. grid0.addWidget(self.multicolored_cb, 0, 2)
  355. ## Isolation Routing
  356. self.isolation_routing_label = QtGui.QLabel("<b>Isolation Routing:</b>")
  357. self.isolation_routing_label.setToolTip(
  358. "Create a Geometry object with\n"
  359. "toolpaths to cut outside polygons."
  360. )
  361. self.custom_box.addWidget(self.isolation_routing_label)
  362. grid1 = QtGui.QGridLayout()
  363. self.custom_box.addLayout(grid1)
  364. tdlabel = QtGui.QLabel('Tool dia:')
  365. tdlabel.setToolTip(
  366. "Diameter of the cutting tool."
  367. )
  368. grid1.addWidget(tdlabel, 0, 0)
  369. self.iso_tool_dia_entry = LengthEntry()
  370. grid1.addWidget(self.iso_tool_dia_entry, 0, 1)
  371. passlabel = QtGui.QLabel('Width (# passes):')
  372. passlabel.setToolTip(
  373. "Width of the isolation gap in\n"
  374. "number (integer) of tool widths."
  375. )
  376. grid1.addWidget(passlabel, 1, 0)
  377. self.iso_width_entry = IntEntry()
  378. grid1.addWidget(self.iso_width_entry, 1, 1)
  379. overlabel = QtGui.QLabel('Pass overlap:')
  380. overlabel.setToolTip(
  381. "How much (fraction of tool width)\n"
  382. "to overlap each pass."
  383. )
  384. grid1.addWidget(overlabel, 2, 0)
  385. self.iso_overlap_entry = FloatEntry()
  386. grid1.addWidget(self.iso_overlap_entry, 2, 1)
  387. self.generate_iso_button = QtGui.QPushButton('Generate Geometry')
  388. self.generate_iso_button.setToolTip(
  389. "Create the Geometry Object\n"
  390. "for isolation routing."
  391. )
  392. self.custom_box.addWidget(self.generate_iso_button)
  393. ## Board cuttout
  394. self.board_cutout_label = QtGui.QLabel("<b>Board cutout:</b>")
  395. self.board_cutout_label.setToolTip(
  396. "Create toolpaths to cut around\n"
  397. "the PCB and separate it from\n"
  398. "the original board."
  399. )
  400. self.custom_box.addWidget(self.board_cutout_label)
  401. grid2 = QtGui.QGridLayout()
  402. self.custom_box.addLayout(grid2)
  403. tdclabel = QtGui.QLabel('Tool dia:')
  404. tdclabel.setToolTip(
  405. "Diameter of the cutting tool."
  406. )
  407. grid2.addWidget(tdclabel, 0, 0)
  408. self.cutout_tooldia_entry = LengthEntry()
  409. grid2.addWidget(self.cutout_tooldia_entry, 0, 1)
  410. marginlabel = QtGui.QLabel('Margin:')
  411. marginlabel.setToolTip(
  412. "Distance from objects at which\n"
  413. "to draw the cutout."
  414. )
  415. grid2.addWidget(marginlabel, 1, 0)
  416. self.cutout_margin_entry = LengthEntry()
  417. grid2.addWidget(self.cutout_margin_entry, 1, 1)
  418. gaplabel = QtGui.QLabel('Gap size:')
  419. gaplabel.setToolTip(
  420. "Size of the gaps in the toolpath\n"
  421. "that will remain to hold the\n"
  422. "board in place."
  423. )
  424. grid2.addWidget(gaplabel, 2, 0)
  425. self.cutout_gap_entry = LengthEntry()
  426. grid2.addWidget(self.cutout_gap_entry, 2, 1)
  427. gapslabel = QtGui.QLabel('Gaps:')
  428. gapslabel.setToolTip(
  429. "Where to place the gaps, Top/Bottom\n"
  430. "Left/Rigt, or on all 4 sides."
  431. )
  432. grid2.addWidget(gapslabel, 3, 0)
  433. self.gaps_radio = RadioSet([{'label': '2 (T/B)', 'value': 'tb'},
  434. {'label': '2 (L/R)', 'value': 'lr'},
  435. {'label': '4', 'value': '4'}])
  436. grid2.addWidget(self.gaps_radio, 3, 1)
  437. self.generate_cutout_button = QtGui.QPushButton('Generate Geometry')
  438. self.generate_cutout_button.setToolTip(
  439. "Generate the geometry for\n"
  440. "the board cutout."
  441. )
  442. self.custom_box.addWidget(self.generate_cutout_button)
  443. ## Non-copper regions
  444. self.noncopper_label = QtGui.QLabel("<b>Non-copper regions:</b>")
  445. self.noncopper_label.setToolTip(
  446. "Create polygons covering the\n"
  447. "areas without copper on the PCB.\n"
  448. "Equivalent to the inverse of this\n"
  449. "object. Can be used to remove all\n"
  450. "copper from a specified region."
  451. )
  452. self.custom_box.addWidget(self.noncopper_label)
  453. grid3 = QtGui.QGridLayout()
  454. self.custom_box.addLayout(grid3)
  455. # Margin
  456. bmlabel = QtGui.QLabel('Boundary Margin:')
  457. bmlabel.setToolTip(
  458. "Specify the edge of the PCB\n"
  459. "by drawing a box around all\n"
  460. "objects with this minimum\n"
  461. "distance."
  462. )
  463. grid3.addWidget(bmlabel, 0, 0)
  464. self.noncopper_margin_entry = LengthEntry()
  465. grid3.addWidget(self.noncopper_margin_entry, 0, 1)
  466. # Rounded corners
  467. self.noncopper_rounded_cb = FCCheckBox(label="Rounded corners")
  468. self.noncopper_rounded_cb.setToolTip(
  469. "Creates a Geometry objects with polygons\n"
  470. "covering the copper-free areas of the PCB."
  471. )
  472. grid3.addWidget(self.noncopper_rounded_cb, 1, 0, 1, 2)
  473. self.generate_noncopper_button = QtGui.QPushButton('Generate Geometry')
  474. self.custom_box.addWidget(self.generate_noncopper_button)
  475. ## Bounding box
  476. self.boundingbox_label = QtGui.QLabel('<b>Bounding Box:</b>')
  477. self.custom_box.addWidget(self.boundingbox_label)
  478. grid4 = QtGui.QGridLayout()
  479. self.custom_box.addLayout(grid4)
  480. bbmargin = QtGui.QLabel('Boundary Margin:')
  481. bbmargin.setToolTip(
  482. "Distance of the edges of the box\n"
  483. "to the nearest polygon."
  484. )
  485. grid4.addWidget(bbmargin, 0, 0)
  486. self.bbmargin_entry = LengthEntry()
  487. grid4.addWidget(self.bbmargin_entry, 0, 1)
  488. self.bbrounded_cb = FCCheckBox(label="Rounded corners")
  489. self.bbrounded_cb.setToolTip(
  490. "If the bounding box is \n"
  491. "to have rounded corners\n"
  492. "their radius is equal to\n"
  493. "the margin."
  494. )
  495. grid4.addWidget(self.bbrounded_cb, 1, 0, 1, 2)
  496. self.generate_bb_button = QtGui.QPushButton('Generate Geometry')
  497. self.generate_bb_button.setToolTip(
  498. "Genrate the Geometry object."
  499. )
  500. self.custom_box.addWidget(self.generate_bb_button)
  501. # def main():
  502. #
  503. # app = QtGui.QApplication(sys.argv)
  504. # fc = GerberObjectUI()
  505. # sys.exit(app.exec_())
  506. #
  507. #
  508. # if __name__ == '__main__':
  509. # main()