FlatCAMGUI.py 35 KB

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