FlatCAMGUI.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. ############################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # Author: Juan Pablo Caram (c) #
  5. # Date: 2/5/2014 #
  6. # MIT Licence #
  7. ############################################################
  8. from PyQt4 import QtGui, QtCore, Qt
  9. from GUIElements import *
  10. class FlatCAMGUI(QtGui.QMainWindow):
  11. # Emitted when persistent window geometry needs to be retained
  12. geom_update = QtCore.pyqtSignal(int, int, int, int, name='geomUpdate')
  13. def __init__(self, version, name=None):
  14. super(FlatCAMGUI, self).__init__()
  15. # Divine icon pack by Ipapun @ finicons.com
  16. ############
  17. ### Menu ###
  18. ############
  19. self.menu = self.menuBar()
  20. ### File ###
  21. self.menufile = self.menu.addMenu('&File')
  22. # New
  23. self.menufilenew = QtGui.QAction(QtGui.QIcon('share/file16.png'), '&New', self)
  24. self.menufile.addAction(self.menufilenew)
  25. # Open recent
  26. # Recent
  27. self.recent = self.menufile.addMenu(QtGui.QIcon('share/folder16.png'), "Open recent ...")
  28. # Open gerber ...
  29. self.menufileopengerber = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Open &Gerber ...', self)
  30. self.menufile.addAction(self.menufileopengerber)
  31. # Open Excellon ...
  32. self.menufileopenexcellon = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Open &Excellon ...', self)
  33. self.menufile.addAction(self.menufileopenexcellon)
  34. # Open G-Code ...
  35. self.menufileopengcode = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Open G-&Code ...', self)
  36. self.menufile.addAction(self.menufileopengcode)
  37. # Open Project ...
  38. self.menufileopenproject = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Open &Project ...', self)
  39. self.menufile.addAction(self.menufileopenproject)
  40. # Import SVG ...
  41. self.menufileimportsvg = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Import &SVG ...', self)
  42. self.menufile.addAction(self.menufileimportsvg)
  43. # Export SVG ...
  44. self.menufileexportsvg = QtGui.QAction(QtGui.QIcon('share/folder16.png'), 'Export &SVG ...', self)
  45. self.menufile.addAction(self.menufileexportsvg)
  46. # Save Project
  47. self.menufilesaveproject = QtGui.QAction(QtGui.QIcon('share/floppy16.png'), '&Save Project', self)
  48. self.menufile.addAction(self.menufilesaveproject)
  49. # Save Project As ...
  50. self.menufilesaveprojectas = QtGui.QAction(QtGui.QIcon('share/floppy16.png'), 'Save Project &As ...', self)
  51. self.menufile.addAction(self.menufilesaveprojectas)
  52. # Save Project Copy ...
  53. self.menufilesaveprojectcopy = QtGui.QAction(QtGui.QIcon('share/floppy16.png'), 'Save Project C&opy ...', self)
  54. self.menufile.addAction(self.menufilesaveprojectcopy)
  55. # Save Defaults
  56. self.menufilesavedefaults = QtGui.QAction(QtGui.QIcon('share/floppy16.png'), 'Save &Defaults', self)
  57. self.menufile.addAction(self.menufilesavedefaults)
  58. # Quit
  59. self.exit_action = QtGui.QAction(QtGui.QIcon('share/power16.png'), '&Exit', self)
  60. # exitAction.setShortcut('Ctrl+Q')
  61. # exitAction.setStatusTip('Exit application')
  62. #self.exit_action.triggered.connect(QtGui.qApp.quit)
  63. self.menufile.addAction(self.exit_action)
  64. ### Edit ###
  65. self.menuedit = self.menu.addMenu('&Edit')
  66. self.menueditnew = self.menuedit.addAction(QtGui.QIcon('share/new_geo16.png'), 'New Geometry')
  67. self.menueditedit = self.menuedit.addAction(QtGui.QIcon('share/edit16.png'), 'Edit Geometry')
  68. self.menueditok = self.menuedit.addAction(QtGui.QIcon('share/edit_ok16.png'), 'Update Geometry')
  69. #self.menueditok.
  70. #self.menueditcancel = self.menuedit.addAction(QtGui.QIcon('share/cancel_edit16.png'), "Cancel Edit")
  71. self.menueditjoin = self.menuedit.addAction(QtGui.QIcon('share/join16.png'), 'Join Geometry')
  72. self.menueditdelete = self.menuedit.addAction(QtGui.QIcon('share/trash16.png'), 'Delete')
  73. ### Options ###
  74. self.menuoptions = self.menu.addMenu('&Options')
  75. self.menuoptions_transfer = self.menuoptions.addMenu('Transfer options')
  76. self.menuoptions_transfer_a2p = self.menuoptions_transfer.addAction("Application to Project")
  77. self.menuoptions_transfer_p2a = self.menuoptions_transfer.addAction("Project to Application")
  78. self.menuoptions_transfer_p2o = self.menuoptions_transfer.addAction("Project to Object")
  79. self.menuoptions_transfer_o2p = self.menuoptions_transfer.addAction("Object to Project")
  80. self.menuoptions_transfer_a2o = self.menuoptions_transfer.addAction("Application to Object")
  81. self.menuoptions_transfer_o2a = self.menuoptions_transfer.addAction("Object to Application")
  82. ### View ###
  83. self.menuview = self.menu.addMenu('&View')
  84. self.menuviewdisableall = self.menuview.addAction(QtGui.QIcon('share/clear_plot16.png'), 'Disable all plots')
  85. self.menuviewdisableother = self.menuview.addAction(QtGui.QIcon('share/clear_plot16.png'),
  86. 'Disable all plots but this one')
  87. self.menuviewenable = self.menuview.addAction(QtGui.QIcon('share/replot16.png'), 'Enable all plots')
  88. ### Tool ###
  89. #self.menutool = self.menu.addMenu('&Tool')
  90. self.menutool = QtGui.QMenu('&Tool')
  91. self.menutoolaction = self.menu.addMenu(self.menutool)
  92. self.menutoolshell = self.menutool.addAction(QtGui.QIcon('share/shell16.png'), '&Command Line')
  93. ### Help ###
  94. self.menuhelp = self.menu.addMenu('&Help')
  95. self.menuhelp_about = self.menuhelp.addAction(QtGui.QIcon('share/tv16.png'), 'About FlatCAM')
  96. self.menuhelp_home = self.menuhelp.addAction(QtGui.QIcon('share/home16.png'), 'Home')
  97. self.menuhelp_manual = self.menuhelp.addAction(QtGui.QIcon('share/globe16.png'), 'Manual')
  98. ###############
  99. ### Toolbar ###
  100. ###############
  101. self.toolbar = QtGui.QToolBar()
  102. self.addToolBar(self.toolbar)
  103. self.zoom_fit_btn = self.toolbar.addAction(QtGui.QIcon('share/zoom_fit32.png'), "&Zoom Fit")
  104. self.zoom_out_btn = self.toolbar.addAction(QtGui.QIcon('share/zoom_out32.png'), "&Zoom Out")
  105. self.zoom_in_btn = self.toolbar.addAction(QtGui.QIcon('share/zoom_in32.png'), "&Zoom In")
  106. self.clear_plot_btn = self.toolbar.addAction(QtGui.QIcon('share/clear_plot32.png'), "&Clear Plot")
  107. self.replot_btn = self.toolbar.addAction(QtGui.QIcon('share/replot32.png'), "&Replot")
  108. self.newgeo_btn = self.toolbar.addAction(QtGui.QIcon('share/new_geo32.png'), "New Blank Geometry")
  109. self.editgeo_btn = self.toolbar.addAction(QtGui.QIcon('share/edit32.png'), "Edit Geometry")
  110. self.updategeo_btn = self.toolbar.addAction(QtGui.QIcon('share/edit_ok32.png'), "Update Geometry")
  111. self.updategeo_btn.setEnabled(False)
  112. #self.canceledit_btn = self.toolbar.addAction(QtGui.QIcon('share/cancel_edit32.png'), "Cancel Edit")
  113. self.delete_btn = self.toolbar.addAction(QtGui.QIcon('share/delete32.png'), "&Delete")
  114. self.shell_btn = self.toolbar.addAction(QtGui.QIcon('share/shell32.png'), "&Command Line")
  115. ################
  116. ### Splitter ###
  117. ################
  118. self.splitter = QtGui.QSplitter()
  119. self.setCentralWidget(self.splitter)
  120. ################
  121. ### Notebook ###
  122. ################
  123. self.notebook = QtGui.QTabWidget()
  124. # self.notebook.setMinimumWidth(250)
  125. ### Projet ###
  126. project_tab = QtGui.QWidget()
  127. project_tab.setMinimumWidth(250) # Hack
  128. self.project_tab_layout = QtGui.QVBoxLayout(project_tab)
  129. self.project_tab_layout.setContentsMargins(2, 2, 2, 2)
  130. self.notebook.addTab(project_tab, "Project")
  131. ### Selected ###
  132. self.selected_tab = QtGui.QWidget()
  133. self.selected_tab_layout = QtGui.QVBoxLayout(self.selected_tab)
  134. self.selected_tab_layout.setContentsMargins(2, 2, 2, 2)
  135. self.selected_scroll_area = VerticalScrollArea()
  136. self.selected_tab_layout.addWidget(self.selected_scroll_area)
  137. self.notebook.addTab(self.selected_tab, "Selected")
  138. ### Options ###
  139. self.options_tab = QtGui.QWidget()
  140. self.options_tab.setContentsMargins(0, 0, 0, 0)
  141. self.options_tab_layout = QtGui.QVBoxLayout(self.options_tab)
  142. self.options_tab_layout.setContentsMargins(2, 2, 2, 2)
  143. hlay1 = QtGui.QHBoxLayout()
  144. self.options_tab_layout.addLayout(hlay1)
  145. self.icon = QtGui.QLabel()
  146. self.icon.setPixmap(QtGui.QPixmap('share/gear48.png'))
  147. hlay1.addWidget(self.icon)
  148. self.options_combo = QtGui.QComboBox()
  149. self.options_combo.addItem("APPLICATION DEFAULTS")
  150. self.options_combo.addItem("PROJECT OPTIONS")
  151. hlay1.addWidget(self.options_combo)
  152. hlay1.addStretch()
  153. self.options_scroll_area = VerticalScrollArea()
  154. self.options_tab_layout.addWidget(self.options_scroll_area)
  155. self.notebook.addTab(self.options_tab, "Options")
  156. ### Tool ###
  157. self.tool_tab = QtGui.QWidget()
  158. self.tool_tab_layout = QtGui.QVBoxLayout(self.tool_tab)
  159. self.tool_tab_layout.setContentsMargins(2, 2, 2, 2)
  160. self.notebook.addTab(self.tool_tab, "Tool")
  161. self.tool_scroll_area = VerticalScrollArea()
  162. self.tool_tab_layout.addWidget(self.tool_scroll_area)
  163. self.splitter.addWidget(self.notebook)
  164. ######################
  165. ### Plot and other ###
  166. ######################
  167. right_widget = QtGui.QWidget()
  168. # right_widget.setContentsMargins(0, 0, 0, 0)
  169. self.splitter.addWidget(right_widget)
  170. self.right_layout = QtGui.QVBoxLayout()
  171. self.right_layout.setMargin(0)
  172. # self.right_layout.setContentsMargins(0, 0, 0, 0)
  173. right_widget.setLayout(self.right_layout)
  174. ################
  175. ### Info bar ###
  176. ################
  177. infobar = self.statusBar()
  178. #self.info_label = QtGui.QLabel("Welcome to FlatCAM.")
  179. #self.info_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
  180. #infobar.addWidget(self.info_label, stretch=1)
  181. self.fcinfo = FlatCAMInfoBar()
  182. infobar.addWidget(self.fcinfo, stretch=1)
  183. self.position_label = QtGui.QLabel("")
  184. #self.position_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
  185. self.position_label.setMinimumWidth(110)
  186. infobar.addWidget(self.position_label)
  187. self.units_label = QtGui.QLabel("[in]")
  188. # self.units_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
  189. self.units_label.setMargin(2)
  190. infobar.addWidget(self.units_label)
  191. self.progress_bar = QtGui.QProgressBar()
  192. self.progress_bar.setMinimum(0)
  193. self.progress_bar.setMaximum(100)
  194. #infobar.addWidget(self.progress_bar)
  195. self.activity_view = FlatCAMActivityView()
  196. infobar.addWidget(self.activity_view)
  197. #############
  198. ### Icons ###
  199. #############
  200. self.app_icon = QtGui.QIcon()
  201. self.app_icon.addFile('share/flatcam_icon16.png', QtCore.QSize(16, 16))
  202. self.app_icon.addFile('share/flatcam_icon24.png', QtCore.QSize(24, 24))
  203. self.app_icon.addFile('share/flatcam_icon32.png', QtCore.QSize(32, 32))
  204. self.app_icon.addFile('share/flatcam_icon48.png', QtCore.QSize(48, 48))
  205. self.app_icon.addFile('share/flatcam_icon128.png', QtCore.QSize(128, 128))
  206. self.app_icon.addFile('share/flatcam_icon256.png', QtCore.QSize(256, 256))
  207. self.setWindowIcon(self.app_icon)
  208. self.setGeometry(100, 100, 1024, 650)
  209. title = 'FlatCAM {}'.format(version)
  210. if name is not None:
  211. title += ' - {}'.format(name)
  212. self.setWindowTitle(title)
  213. self.show()
  214. def closeEvent(self, event):
  215. grect = self.geometry()
  216. self.geom_update.emit(grect.x(), grect.y(), grect.width(), grect.height())
  217. QtGui.qApp.quit()
  218. class FlatCAMActivityView(QtGui.QWidget):
  219. def __init__(self, parent=None):
  220. super(FlatCAMActivityView, self).__init__(parent=parent)
  221. self.setMinimumWidth(200)
  222. self.icon = QtGui.QLabel(self)
  223. self.icon.setGeometry(0, 0, 12, 12)
  224. self.movie = QtGui.QMovie("share/active.gif")
  225. self.icon.setMovie(self.movie)
  226. #self.movie.start()
  227. layout = QtGui.QHBoxLayout()
  228. layout.setContentsMargins(5, 0, 5, 0)
  229. layout.setAlignment(QtCore.Qt.AlignLeft)
  230. self.setLayout(layout)
  231. layout.addWidget(self.icon)
  232. self.text = QtGui.QLabel(self)
  233. self.text.setText("Idle.")
  234. layout.addWidget(self.text)
  235. def set_idle(self):
  236. self.movie.stop()
  237. self.text.setText("Idle.")
  238. def set_busy(self, msg):
  239. self.movie.start()
  240. self.text.setText(msg)
  241. class FlatCAMInfoBar(QtGui.QWidget):
  242. def __init__(self, parent=None):
  243. super(FlatCAMInfoBar, self).__init__(parent=parent)
  244. self.icon = QtGui.QLabel(self)
  245. self.icon.setGeometry(0, 0, 12, 12)
  246. self.pmap = QtGui.QPixmap('share/graylight12.png')
  247. self.icon.setPixmap(self.pmap)
  248. layout = QtGui.QHBoxLayout()
  249. layout.setContentsMargins(5, 0, 5, 0)
  250. self.setLayout(layout)
  251. layout.addWidget(self.icon)
  252. self.text = QtGui.QLabel(self)
  253. self.text.setText("Hello!")
  254. self.text.setToolTip("Hello!")
  255. layout.addWidget(self.text)
  256. layout.addStretch()
  257. def set_text_(self, text):
  258. self.text.setText(text)
  259. self.text.setToolTip(text)
  260. def set_status(self, text, level="info"):
  261. level = str(level)
  262. self.pmap.fill()
  263. if level == "error":
  264. self.pmap = QtGui.QPixmap('share/redlight12.png')
  265. elif level == "success":
  266. self.pmap = QtGui.QPixmap('share/greenlight12.png')
  267. elif level == "warning":
  268. self.pmap = QtGui.QPixmap('share/yellowlight12.png')
  269. else:
  270. self.pmap = QtGui.QPixmap('share/graylight12.png')
  271. self.icon.setPixmap(self.pmap)
  272. self.set_text_(text)
  273. class OptionsGroupUI(QtGui.QGroupBox):
  274. def __init__(self, title, parent=None):
  275. QtGui.QGroupBox.__init__(self, title, parent=parent)
  276. self.setStyleSheet("""
  277. QGroupBox
  278. {
  279. font-size: 16px;
  280. font-weight: bold;
  281. }
  282. """)
  283. self.layout = QtGui.QVBoxLayout()
  284. self.setLayout(self.layout)
  285. class GerberOptionsGroupUI(OptionsGroupUI):
  286. def __init__(self, parent=None):
  287. OptionsGroupUI.__init__(self, "Gerber Options", parent=parent)
  288. ## Plot options
  289. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  290. self.layout.addWidget(self.plot_options_label)
  291. grid0 = QtGui.QGridLayout()
  292. self.layout.addLayout(grid0)
  293. # Plot CB
  294. self.plot_cb = FCCheckBox(label='Plot')
  295. self.plot_options_label.setToolTip(
  296. "Plot (show) this object."
  297. )
  298. grid0.addWidget(self.plot_cb, 0, 0)
  299. # Solid CB
  300. self.solid_cb = FCCheckBox(label='Solid')
  301. self.solid_cb.setToolTip(
  302. "Solid color polygons."
  303. )
  304. grid0.addWidget(self.solid_cb, 0, 1)
  305. # Multicolored CB
  306. self.multicolored_cb = FCCheckBox(label='Multicolored')
  307. self.multicolored_cb.setToolTip(
  308. "Draw polygons in different colors."
  309. )
  310. grid0.addWidget(self.multicolored_cb, 0, 2)
  311. ## Isolation Routing
  312. self.isolation_routing_label = QtGui.QLabel("<b>Isolation Routing:</b>")
  313. self.isolation_routing_label.setToolTip(
  314. "Create a Geometry object with\n"
  315. "toolpaths to cut outside polygons."
  316. )
  317. self.layout.addWidget(self.isolation_routing_label)
  318. grid1 = QtGui.QGridLayout()
  319. self.layout.addLayout(grid1)
  320. tdlabel = QtGui.QLabel('Tool dia:')
  321. tdlabel.setToolTip(
  322. "Diameter of the cutting tool."
  323. )
  324. grid1.addWidget(tdlabel, 0, 0)
  325. self.iso_tool_dia_entry = LengthEntry()
  326. grid1.addWidget(self.iso_tool_dia_entry, 0, 1)
  327. passlabel = QtGui.QLabel('Width (# passes):')
  328. passlabel.setToolTip(
  329. "Width of the isolation gap in\n"
  330. "number (integer) of tool widths."
  331. )
  332. grid1.addWidget(passlabel, 1, 0)
  333. self.iso_width_entry = IntEntry()
  334. grid1.addWidget(self.iso_width_entry, 1, 1)
  335. overlabel = QtGui.QLabel('Pass overlap:')
  336. overlabel.setToolTip(
  337. "How much (fraction of tool width)\n"
  338. "to overlap each pass."
  339. )
  340. grid1.addWidget(overlabel, 2, 0)
  341. self.iso_overlap_entry = FloatEntry()
  342. grid1.addWidget(self.iso_overlap_entry, 2, 1)
  343. self.combine_passes_cb = FCCheckBox(label='Combine Passes')
  344. self.combine_passes_cb.setToolTip(
  345. "Combine all passes into one object"
  346. )
  347. grid1.addWidget(self.combine_passes_cb, 3, 0)
  348. ## Board cuttout
  349. self.board_cutout_label = QtGui.QLabel("<b>Board cutout:</b>")
  350. self.board_cutout_label.setToolTip(
  351. "Create toolpaths to cut around\n"
  352. "the PCB and separate it from\n"
  353. "the original board."
  354. )
  355. self.layout.addWidget(self.board_cutout_label)
  356. grid2 = QtGui.QGridLayout()
  357. self.layout.addLayout(grid2)
  358. tdclabel = QtGui.QLabel('Tool dia:')
  359. tdclabel.setToolTip(
  360. "Diameter of the cutting tool."
  361. )
  362. grid2.addWidget(tdclabel, 0, 0)
  363. self.cutout_tooldia_entry = LengthEntry()
  364. grid2.addWidget(self.cutout_tooldia_entry, 0, 1)
  365. marginlabel = QtGui.QLabel('Margin:')
  366. marginlabel.setToolTip(
  367. "Distance from objects at which\n"
  368. "to draw the cutout."
  369. )
  370. grid2.addWidget(marginlabel, 1, 0)
  371. self.cutout_margin_entry = LengthEntry()
  372. grid2.addWidget(self.cutout_margin_entry, 1, 1)
  373. gaplabel = QtGui.QLabel('Gap size:')
  374. gaplabel.setToolTip(
  375. "Size of the gaps in the toolpath\n"
  376. "that will remain to hold the\n"
  377. "board in place."
  378. )
  379. grid2.addWidget(gaplabel, 2, 0)
  380. self.cutout_gap_entry = LengthEntry()
  381. grid2.addWidget(self.cutout_gap_entry, 2, 1)
  382. gapslabel = QtGui.QLabel('Gaps:')
  383. gapslabel.setToolTip(
  384. "Where to place the gaps, Top/Bottom\n"
  385. "Left/Rigt, or on all 4 sides."
  386. )
  387. grid2.addWidget(gapslabel, 3, 0)
  388. self.gaps_radio = RadioSet([{'label': '2 (T/B)', 'value': 'tb'},
  389. {'label': '2 (L/R)', 'value': 'lr'},
  390. {'label': '4', 'value': '4'}])
  391. grid2.addWidget(self.gaps_radio, 3, 1)
  392. ## Non-copper regions
  393. self.noncopper_label = QtGui.QLabel("<b>Non-copper regions:</b>")
  394. self.noncopper_label.setToolTip(
  395. "Create polygons covering the\n"
  396. "areas without copper on the PCB.\n"
  397. "Equivalent to the inverse of this\n"
  398. "object. Can be used to remove all\n"
  399. "copper from a specified region."
  400. )
  401. self.layout.addWidget(self.noncopper_label)
  402. grid3 = QtGui.QGridLayout()
  403. self.layout.addLayout(grid3)
  404. # Margin
  405. bmlabel = QtGui.QLabel('Boundary Margin:')
  406. bmlabel.setToolTip(
  407. "Specify the edge of the PCB\n"
  408. "by drawing a box around all\n"
  409. "objects with this minimum\n"
  410. "distance."
  411. )
  412. grid3.addWidget(bmlabel, 0, 0)
  413. self.noncopper_margin_entry = LengthEntry()
  414. grid3.addWidget(self.noncopper_margin_entry, 0, 1)
  415. # Rounded corners
  416. self.noncopper_rounded_cb = FCCheckBox(label="Rounded corners")
  417. self.noncopper_rounded_cb.setToolTip(
  418. "Creates a Geometry objects with polygons\n"
  419. "covering the copper-free areas of the PCB."
  420. )
  421. grid3.addWidget(self.noncopper_rounded_cb, 1, 0, 1, 2)
  422. ## Bounding box
  423. self.boundingbox_label = QtGui.QLabel('<b>Bounding Box:</b>')
  424. self.layout.addWidget(self.boundingbox_label)
  425. grid4 = QtGui.QGridLayout()
  426. self.layout.addLayout(grid4)
  427. bbmargin = QtGui.QLabel('Boundary Margin:')
  428. bbmargin.setToolTip(
  429. "Distance of the edges of the box\n"
  430. "to the nearest polygon."
  431. )
  432. grid4.addWidget(bbmargin, 0, 0)
  433. self.bbmargin_entry = LengthEntry()
  434. grid4.addWidget(self.bbmargin_entry, 0, 1)
  435. self.bbrounded_cb = FCCheckBox(label="Rounded corners")
  436. self.bbrounded_cb.setToolTip(
  437. "If the bounding box is \n"
  438. "to have rounded corners\n"
  439. "their radius is equal to\n"
  440. "the margin."
  441. )
  442. grid4.addWidget(self.bbrounded_cb, 1, 0, 1, 2)
  443. class ExcellonOptionsGroupUI(OptionsGroupUI):
  444. def __init__(self, parent=None):
  445. OptionsGroupUI.__init__(self, "Excellon Options", parent=parent)
  446. ## Plot options
  447. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  448. self.layout.addWidget(self.plot_options_label)
  449. grid0 = QtGui.QGridLayout()
  450. self.layout.addLayout(grid0)
  451. self.plot_cb = FCCheckBox(label='Plot')
  452. self.plot_cb.setToolTip(
  453. "Plot (show) this object."
  454. )
  455. grid0.addWidget(self.plot_cb, 0, 0)
  456. self.solid_cb = FCCheckBox(label='Solid')
  457. self.solid_cb.setToolTip(
  458. "Solid circles."
  459. )
  460. grid0.addWidget(self.solid_cb, 0, 1)
  461. ## Create CNC Job
  462. self.cncjob_label = QtGui.QLabel('<b>Create CNC Job</b>')
  463. self.cncjob_label.setToolTip(
  464. "Create a CNC Job object\n"
  465. "for this drill object."
  466. )
  467. self.layout.addWidget(self.cncjob_label)
  468. grid1 = QtGui.QGridLayout()
  469. self.layout.addLayout(grid1)
  470. cutzlabel = QtGui.QLabel('Cut Z:')
  471. cutzlabel.setToolTip(
  472. "Drill depth (negative)\n"
  473. "below the copper surface."
  474. )
  475. grid1.addWidget(cutzlabel, 0, 0)
  476. self.cutz_entry = LengthEntry()
  477. grid1.addWidget(self.cutz_entry, 0, 1)
  478. travelzlabel = QtGui.QLabel('Travel Z:')
  479. travelzlabel.setToolTip(
  480. "Tool height when travelling\n"
  481. "across the XY plane."
  482. )
  483. grid1.addWidget(travelzlabel, 1, 0)
  484. self.travelz_entry = LengthEntry()
  485. grid1.addWidget(self.travelz_entry, 1, 1)
  486. frlabel = QtGui.QLabel('Feed rate:')
  487. frlabel.setToolTip(
  488. "Tool speed while drilling\n"
  489. "(in units per minute)."
  490. )
  491. grid1.addWidget(frlabel, 2, 0)
  492. self.feedrate_entry = LengthEntry()
  493. grid1.addWidget(self.feedrate_entry, 2, 1)
  494. toolchangezlabel = QtGui.QLabel('Toolchange Z:')
  495. toolchangezlabel.setToolTip(
  496. "Tool Z where user can change drill bit\n"
  497. )
  498. grid1.addWidget(toolchangezlabel, 3, 0)
  499. self.toolchangez_entry = LengthEntry()
  500. grid1.addWidget(self.toolchangez_entry, 3, 1)
  501. spdlabel = QtGui.QLabel('Spindle speed:')
  502. spdlabel.setToolTip(
  503. "Speed of the spindle\n"
  504. "in RPM (optional)"
  505. )
  506. grid1.addWidget(spdlabel, 4, 0)
  507. self.spindlespeed_entry = IntEntry(allow_empty=True)
  508. grid1.addWidget(self.spindlespeed_entry, 4, 1)
  509. #### Milling Holes ####
  510. self.mill_hole_label = QtGui.QLabel('<b>Mill Holes</b>')
  511. self.mill_hole_label.setToolTip(
  512. "Create Geometry for milling holes."
  513. )
  514. self.layout.addWidget(self.mill_hole_label)
  515. grid1 = QtGui.QGridLayout()
  516. self.layout.addLayout(grid1)
  517. tdlabel = QtGui.QLabel('Tool dia:')
  518. tdlabel.setToolTip(
  519. "Diameter of the cutting tool."
  520. )
  521. grid1.addWidget(tdlabel, 0, 0)
  522. self.tooldia_entry = LengthEntry()
  523. grid1.addWidget(self.tooldia_entry, 0, 1)
  524. class GeometryOptionsGroupUI(OptionsGroupUI):
  525. def __init__(self, parent=None):
  526. OptionsGroupUI.__init__(self, "Geometry Options", parent=parent)
  527. ## Plot options
  528. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  529. self.layout.addWidget(self.plot_options_label)
  530. # Plot CB
  531. self.plot_cb = FCCheckBox(label='Plot')
  532. self.plot_cb.setToolTip(
  533. "Plot (show) this object."
  534. )
  535. self.layout.addWidget(self.plot_cb)
  536. # ------------------------------
  537. ## Create CNC Job
  538. # ------------------------------
  539. self.cncjob_label = QtGui.QLabel('<b>Create CNC Job:</b>')
  540. self.cncjob_label.setToolTip(
  541. "Create a CNC Job object\n"
  542. "tracing the contours of this\n"
  543. "Geometry object."
  544. )
  545. self.layout.addWidget(self.cncjob_label)
  546. grid1 = QtGui.QGridLayout()
  547. self.layout.addLayout(grid1)
  548. cutzlabel = QtGui.QLabel('Cut Z:')
  549. cutzlabel.setToolTip(
  550. "Cutting depth (negative)\n"
  551. "below the copper surface."
  552. )
  553. grid1.addWidget(cutzlabel, 0, 0)
  554. self.cutz_entry = LengthEntry()
  555. grid1.addWidget(self.cutz_entry, 0, 1)
  556. # Travel Z
  557. travelzlabel = QtGui.QLabel('Travel Z:')
  558. travelzlabel.setToolTip(
  559. "Height of the tool when\n"
  560. "moving without cutting."
  561. )
  562. grid1.addWidget(travelzlabel, 1, 0)
  563. self.travelz_entry = LengthEntry()
  564. grid1.addWidget(self.travelz_entry, 1, 1)
  565. # Feedrate
  566. frlabel = QtGui.QLabel('Feed Rate:')
  567. frlabel.setToolTip(
  568. "Cutting speed in the XY\n"
  569. "plane in units per minute"
  570. )
  571. grid1.addWidget(frlabel, 2, 0)
  572. self.cncfeedrate_entry = LengthEntry()
  573. grid1.addWidget(self.cncfeedrate_entry, 2, 1)
  574. # Tooldia
  575. tdlabel = QtGui.QLabel('Tool dia:')
  576. tdlabel.setToolTip(
  577. "The diameter of the cutting\n"
  578. "tool (just for display)."
  579. )
  580. grid1.addWidget(tdlabel, 3, 0)
  581. self.cnctooldia_entry = LengthEntry()
  582. grid1.addWidget(self.cnctooldia_entry, 3, 1)
  583. spdlabel = QtGui.QLabel('Spindle speed:')
  584. spdlabel.setToolTip(
  585. "Speed of the spindle\n"
  586. "in RPM (optional)"
  587. )
  588. grid1.addWidget(spdlabel, 4, 0)
  589. self.cncspindlespeed_entry = IntEntry(allow_empty=True)
  590. grid1.addWidget(self.cncspindlespeed_entry, 4, 1)
  591. # ------------------------------
  592. ## Paint area
  593. # ------------------------------
  594. self.paint_label = QtGui.QLabel('<b>Paint Area:</b>')
  595. self.paint_label.setToolTip(
  596. "Creates tool paths to cover the\n"
  597. "whole area of a polygon (remove\n"
  598. "all copper). You will be asked\n"
  599. "to click on the desired polygon."
  600. )
  601. self.layout.addWidget(self.paint_label)
  602. grid2 = QtGui.QGridLayout()
  603. self.layout.addLayout(grid2)
  604. # Tool dia
  605. ptdlabel = QtGui.QLabel('Tool dia:')
  606. ptdlabel.setToolTip(
  607. "Diameter of the tool to\n"
  608. "be used in the operation."
  609. )
  610. grid2.addWidget(ptdlabel, 0, 0)
  611. self.painttooldia_entry = LengthEntry()
  612. grid2.addWidget(self.painttooldia_entry, 0, 1)
  613. # Overlap
  614. ovlabel = QtGui.QLabel('Overlap:')
  615. ovlabel.setToolTip(
  616. "How much (fraction) of the tool\n"
  617. "width to overlap each tool pass."
  618. )
  619. grid2.addWidget(ovlabel, 1, 0)
  620. self.paintoverlap_entry = LengthEntry()
  621. grid2.addWidget(self.paintoverlap_entry, 1, 1)
  622. # Margin
  623. marginlabel = QtGui.QLabel('Margin:')
  624. marginlabel.setToolTip(
  625. "Distance by which to avoid\n"
  626. "the edges of the polygon to\n"
  627. "be painted."
  628. )
  629. grid2.addWidget(marginlabel, 2, 0)
  630. self.paintmargin_entry = LengthEntry()
  631. grid2.addWidget(self.paintmargin_entry, 2, 1)
  632. # Method
  633. methodlabel = QtGui.QLabel('Method:')
  634. methodlabel.setToolTip(
  635. "Algorithm to paint the polygon:<BR>"
  636. "<B>Standard</B>: Fixed step inwards.<BR>"
  637. "<B>Seed-based</B>: Outwards from seed."
  638. )
  639. grid2.addWidget(methodlabel, 3, 0)
  640. self.paintmethod_combo = RadioSet([
  641. {"label": "Standard", "value": "standard"},
  642. {"label": "Seed-based", "value": "seed"},
  643. {"label": "Straight lines", "value": "lines"}
  644. ], orientation='vertical')
  645. grid2.addWidget(self.paintmethod_combo, 3, 1)
  646. # Connect lines
  647. pathconnectlabel = QtGui.QLabel("Connect:")
  648. pathconnectlabel.setToolTip(
  649. "Draw lines between resulting\n"
  650. "segments to minimize tool lifts."
  651. )
  652. grid2.addWidget(pathconnectlabel, 4, 0)
  653. self.pathconnect_cb = FCCheckBox()
  654. grid2.addWidget(self.pathconnect_cb, 4, 1)
  655. # Paint contour
  656. contourlabel = QtGui.QLabel("Contour:")
  657. contourlabel.setToolTip(
  658. "Cut around the perimeter of the polygon\n"
  659. "to trim rough edges."
  660. )
  661. grid2.addWidget(contourlabel, 5, 0)
  662. self.contour_cb = FCCheckBox()
  663. grid2.addWidget(self.contour_cb, 5, 1)
  664. # Polygon selection
  665. selectlabel = QtGui.QLabel('Selection:')
  666. selectlabel.setToolTip(
  667. "How to select the polygons to paint."
  668. )
  669. grid2.addWidget(selectlabel, 6, 0)
  670. # grid3 = QtGui.QGridLayout()
  671. self.selectmethod_combo = RadioSet([
  672. {"label": "Single", "value": "single"},
  673. {"label": "All", "value": "all"},
  674. # {"label": "Rectangle", "value": "rectangle"}
  675. ])
  676. grid2.addWidget(self.selectmethod_combo, 6, 1)
  677. class CNCJobOptionsGroupUI(OptionsGroupUI):
  678. def __init__(self, parent=None):
  679. OptionsGroupUI.__init__(self, "CNC Job Options", parent=None)
  680. ## Plot options
  681. self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
  682. self.layout.addWidget(self.plot_options_label)
  683. grid0 = QtGui.QGridLayout()
  684. self.layout.addLayout(grid0)
  685. # Plot CB
  686. # self.plot_cb = QtGui.QCheckBox('Plot')
  687. self.plot_cb = FCCheckBox('Plot')
  688. self.plot_cb.setToolTip(
  689. "Plot (show) this object."
  690. )
  691. grid0.addWidget(self.plot_cb, 0, 0)
  692. # Tool dia for plot
  693. tdlabel = QtGui.QLabel('Tool dia:')
  694. tdlabel.setToolTip(
  695. "Diameter of the tool to be\n"
  696. "rendered in the plot."
  697. )
  698. grid0.addWidget(tdlabel, 1, 0)
  699. self.tooldia_entry = LengthEntry()
  700. grid0.addWidget(self.tooldia_entry, 1, 1)
  701. ## Export G-Code
  702. self.export_gcode_label = QtGui.QLabel("<b>Export G-Code:</b>")
  703. self.export_gcode_label.setToolTip(
  704. "Export and save G-Code to\n"
  705. "make this object to a file."
  706. )
  707. self.layout.addWidget(self.export_gcode_label)
  708. # Prepend to G-Code
  709. prependlabel = QtGui.QLabel('Prepend to G-Code:')
  710. prependlabel.setToolTip(
  711. "Type here any G-Code commands you would\n"
  712. "like to add at the beginning of the G-Code file."
  713. )
  714. self.layout.addWidget(prependlabel)
  715. self.prepend_text = FCTextArea()
  716. self.layout.addWidget(self.prepend_text)
  717. # Append text to G-Code
  718. appendlabel = QtGui.QLabel('Append to G-Code:')
  719. appendlabel.setToolTip(
  720. "Type here any G-Code commands you would\n"
  721. "like to append to the generated file.\n"
  722. "I.e.: M2 (End of program)"
  723. )
  724. self.layout.addWidget(appendlabel)
  725. self.append_text = FCTextArea()
  726. self.layout.addWidget(self.append_text)
  727. # Dwell
  728. grid1 = QtGui.QGridLayout()
  729. self.layout.addLayout(grid1)
  730. dwelllabel = QtGui.QLabel('Dwell:')
  731. dwelllabel.setToolTip(
  732. "Pause to allow the spindle to reach its\n"
  733. "speed before cutting."
  734. )
  735. dwelltime = QtGui.QLabel('Duration [sec.]:')
  736. dwelltime.setToolTip(
  737. "Number of second to dwell."
  738. )
  739. self.dwell_cb = FCCheckBox()
  740. self.dwelltime_cb = FCEntry()
  741. grid1.addWidget(dwelllabel, 0, 0)
  742. grid1.addWidget(self.dwell_cb, 0, 1)
  743. grid1.addWidget(dwelltime, 1, 0)
  744. grid1.addWidget(self.dwelltime_cb, 1, 1)
  745. class GlobalOptionsUI(QtGui.QWidget):
  746. """
  747. This is the app and project options editor.
  748. """
  749. def __init__(self, parent=None):
  750. QtGui.QWidget.__init__(self, parent=parent)
  751. layout = QtGui.QVBoxLayout()
  752. self.setLayout(layout)
  753. hlay1 = QtGui.QHBoxLayout()
  754. layout.addLayout(hlay1)
  755. unitslabel = QtGui.QLabel('Units:')
  756. hlay1.addWidget(unitslabel)
  757. self.units_radio = RadioSet([{'label': 'inch', 'value': 'IN'},
  758. {'label': 'mm', 'value': 'MM'}])
  759. hlay1.addWidget(self.units_radio)
  760. ####### Gerber #######
  761. # gerberlabel = QtGui.QLabel('<b>Gerber Options</b>')
  762. # layout.addWidget(gerberlabel)
  763. self.gerber_group = GerberOptionsGroupUI()
  764. # self.gerber_group.setFrameStyle(QtGui.QFrame.StyledPanel)
  765. layout.addWidget(self.gerber_group)
  766. ####### Excellon #######
  767. # excellonlabel = QtGui.QLabel('<b>Excellon Options</b>')
  768. # layout.addWidget(excellonlabel)
  769. self.excellon_group = ExcellonOptionsGroupUI()
  770. # self.excellon_group.setFrameStyle(QtGui.QFrame.StyledPanel)
  771. layout.addWidget(self.excellon_group)
  772. ####### Geometry #######
  773. # geometrylabel = QtGui.QLabel('<b>Geometry Options</b>')
  774. # layout.addWidget(geometrylabel)
  775. self.geometry_group = GeometryOptionsGroupUI()
  776. # self.geometry_group.setStyle(QtGui.QFrame.StyledPanel)
  777. layout.addWidget(self.geometry_group)
  778. ####### CNC #######
  779. # cnclabel = QtGui.QLabel('<b>CNC Job Options</b>')
  780. # layout.addWidget(cnclabel)
  781. self.cncjob_group = CNCJobOptionsGroupUI()
  782. # self.cncjob_group.setStyle(QtGui.QFrame.StyledPanel)
  783. layout.addWidget(self.cncjob_group)
  784. # def main():
  785. #
  786. # app = QtGui.QApplication(sys.argv)
  787. # fc = FlatCAMGUI()
  788. # sys.exit(app.exec_())
  789. #
  790. #
  791. # if __name__ == '__main__':
  792. # main()