FlatCAMGUI.py 35 KB

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